1

I've written an XML Schema file by hand (not using the DataSet Designer in VS) and a corresponding XML file containing structured data to be read in.

I ran the xsd.exe program to generate a Typed DataSet class; on the whole it looks fine to begin with (ignoring how it uses lowercase for public class members), but when it comes to using the generated class nothing happens:

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

At this point all of the typed table members of the MyDataSet class have a .Count of 0.

Strangly enough, I can't get normal DataSets to work either:

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

set.Tables.Count returns 7, which is right, but the tables are all empty.

Am I missing something obvious?

UPDATE:

After doing absolutely nothing set.Tables["extra"].Rows.Count returns the correct number of rows; but when I use a typed dataset it doesn't work, despite everything else being 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 out to console:

19

0

4

1 回答 1

0

问题:xsd.exe 中的代码是否正确生成?例如,您可以在代码中使用生成的 DS、创建 DataRows、将它们添加到 DataTables 等吗?

如果是这样,请尝试手动填写 DS,保存 xml,并与您的结构化 xml 数据文件进行比较,以确保它具有相同的结构。

于 2009-01-09T21:06:50.700 回答