Typed DataSets with XML Data Sources and Schemas

I wrote an XML schema file by hand (not using the DataSet constructor in VS) and a corresponding XML file containing structured data to read.

I ran the xsd.exe program to create the class Typed DataSet

; overall it looks good from the start (ignoring how it uses lowercase for the public members of the class), but when it comes to using the generated class, nothing happens:

MyDataSet set = new MyDataSet();
set.ReadXml( "myData.xml" );

      

At this point, all typed members of the class table MyDataSet

have .Count

of 0.

Oddly enough, I cannot work normally DataSets

:

DataSet set = new DataSet();
set.ReadXmlSchema("mySchema.xsd");
set.ReadXml( "myData.xml");

      

set.Tables.Count

returns 7 which is correct, but all tables are empty.

Am I missing something obvious?

UPDATE:

After absolutely nothing set.Tables["extra"].Rows.Count

returns the correct number of rows; but when I use a typed dataset, it doesn't work, even though everything else is the same:

DataSet ds = new DataSet();
ds.ReadXml( packageExamplePath );

System.Console.WriteLine( ds.Tables["extra"].Rows.Count );

Package st = new Package();
st.ReadXml( packageExamplePath );

System.Console.WriteLine( st.Tables["extra"].Rows.Count );

      

... prints this to the console:

nineteen

0

+1


source to share


1 answer


Question: is the code generated correctly from xsd.exe? For example, can you use the generated DSs in code, create DataRows, add them to DataTables, etc.?



If so, try filling in the DS manually, keeping the xml and comparing against your structured XML data file to make sure it has the same structure.

0


source







All Articles