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

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

问题描述

我使用一个DataGrid来显示一个XML文件。网格的数据源是一种类型化的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)。结果现在我想创建一个新的DataSet对象为每一个新的(分层XML 的)文件我读了。搜索结果创建一个新的DataSet对象是没有问题的但数据类型AREN'T正确的,所以我不能排序他们好(特别是数字字段)。在我看来,我需要创建一个新的类型化的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是一个简单的类可以实例像任何其他class.There没有魔法由工具生成的东西,这些工具简单地生成类,你可以使用这些类以相同的方式使用其他类。搜索结果待办事项 NewDataSet D1 =新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天全站免登陆