tags:

views:

52

answers:

2

I have the following code

           string myXMLfile = @"path to file";
           DataSet ds = new DataSet("myDataset");
           DataTable dataTable = new DataTable("ExtID");
           dataTable.Columns.Add("Ext", typeof(string));
           dataTable.Columns.Add("TargetPath", typeof(string));
           ds.Tables.Add(dataTable);
           ds.ReadXml(myXMLfile);

The dataset contains the columns and the amount of rows is correct but they're all empty. What am I doing wrong

A: 

Does the XML contain the values for a single table? Or for a full dataset (multiple tables, with relationships between them)?

If it's a single data table: try loading the XML on the data table instead:

dataTable.ReadXml(myXMLfile);

Marc

marc_s
A: 

You don't need to create the DataTable if your file already has the right columns. Just do:

DataSet ds = new DataSet(); 
ds.ReadXml("FilePath");

Once it's loaded you can access the data table at ds.Tables[0];