Question: I\'m exporting a System.Data.DataTable to XML. So far it works fine. But I want to have all the data in attributes, which works fine as well. But my problem now, i
Two points:
First: The ExportTable() threw an exception: "DataTable already belongs to another DataSet." When I executed:
ds.Tables.Add(dtt)
I corrected this by making a local copy of the table:
Dim dtX As DataTable = dtt.Copy
ds.Tables.Add(dtX)
ds.DataSetName = strTable
This worked well.
Second: If you use the XML to create a dynamic SQL statement, there is no need to be concerned about the columns/fields with NULL value being omitted in the XML export. Simply walk through the a attributes that are in the XML record, build the INSERT or UPDATE statement and execute a connection command. This is faster than using a DataSet.
For INSERT it has one drawback. If the primary key is created by incrementing an identity column, an ADO.Net DataSet will return it. Dynamic SQL will require a SELECT statement to retrieve it.
Also, it would be good idea to obfuscate your code.