I have the following piece of code:
if (SqlConnection.State == ConnectionState.Open)
{
using (SqlDataAdapter RequestDataAdapter = new SqlDataAdapter("Select * From RequestTabel", SqlConnection))
{
DataSet RequestDataSet = new DataSet("Requests");
RequestDataAdapter.FillSchema(RequestDataSet, SchemaType.Source, "RequestTabel");
RequestDataAdapter.Fill(RequestDataSet, "RequestTabel");
DataTable RequestDataTable;
RequestDataTable = RequestDataSet.Tables["RequestTabel"];
RequestDataSet.WriteXml(@"C:\temp\MyDataset.xml");
}
}
This reads the content of a (database) table to a DataSet, when finished reading it will write to an XMl file.
My problem:
-
Not all columns should end up in the XMl file, how can I exclude/include columns?
-
The XML that WriteXml makes does not include a namespace, how can i add this?
Am i forced to open the XML file after the WriteXml to add the namespace?
- Is it possible to build up the xml using an xsd??
Edit: adjusted the path name 🙂
As for 1: change your
SELECTto only select the columns you need, you can even rename the columns on the fly by usingASto define an alias.As for 2:
DataSetandDataTableboth have a property calledNamespace(for theDataTableproperty see here)which you could set.