创建新的类型化 DataSet 对象 (c#) [英] Create new typed DataSet object (c#)

查看:39
本文介绍了创建新的类型化 DataSet 对象 (c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 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".

这篇关于创建新的类型化 DataSet 对象 (c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆