创建新的类型化 DataSet 对象 (c#)对象、类型、DataSet

2023-09-06 14:06:55 作者:__豪情万纵

我使用 DataGrid 来显示一个 xml 文件.Grid 的 DataSource 是 Typed DataSet.(使用架构)

I use a DataGrid to show a xml file. The Grid's DataSource is a Typed DataSet.(using schema)

    Assembly assembly = Assembly.GetExecutingAssembly();
    Stream stream = assembly.GetManifestResourceStream("XML_Reader.Resources.schema.xsd");
    XmlSchemaSet schemas = new XmlSchemaSet();
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.Schemas.Add(null, XmlReader.Create(stream));
    using (XmlReader reader = XmlReader.Create(xmlFile, settings))
    {
        newDataSet.ReadXml(reader);
    }
    dataGrid.DataSource = newDataSet;

我在我的项目中添加了一个 xsd 架构,并使用 MSDataSetGenerator 来生成 newDataSet.(VS2008).现在我想为我读取的每个新(分层 xml)文件创建一个新的 DataSet 对象.创建一个新的 DataSet 对象不是问题但是数据类型不正确,所以我不能很好地对它们进行排序(特别是数字字段).在我看来,我需要创建一个新的Typed DataSet.那么我该如何解决这个问题呢?

I added a xsd schema to my project and used MSDataSetGenerator to generate the newDataSet. (VS2008). Now i want to create a new DataSet object for every new (hierarchical xml) file i read.Creating a new DataSet object isn't a problem but the data types aren 't correct, so i can't sort them well (specifically the numerical fields). In my view, i need to create a new Typed DataSet. So how can i fix this ?

推荐答案

让我回答我自己的问题 ;-))

Let me answer my own question ;-))

类型化的 DataSet 只是一个可以像任何其他类一样实例化的类.工具生成的任何东西都没有魔法,这些工具只是生成类,您可以像使用其他类一样使用这些类.NewDataSet d1 = new NewDataSet(); 在那里你把正确的类名放在那里而不是NewDataSet".

A typed DataSet is simply a class you can instantiate like any other class.There is no magic to anything generated by tools, those tools simply generate classes and you can use those classes the same way you use other classes.Do NewDataSet d1 = new NewDataSet(); where you put the right class name there instead of "NewDataSet".