反序列化为DataSet - DataType?就像虫子一样。 [英] Deserialize to DataSet - DataType ? acts like bug.

查看:76
本文介绍了反序列化为DataSet - DataType?就像虫子一样。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在之前的帖子中读到,如果列类型设置为Date,我可以获取网格列以按日期时间排序


我反序列化我的XML和一个属性XSD的类型为dateTime,但在检查和行为中

时,数据类型为字符串。如果我在VISSTUDIO中使用GUI预览数据集,它会将我的数据类型显示为dateTime ..


如果我尝试休息数据类型,我会得到这个错误

附加信息:一旦有数据就无法更改列的DataType


这会添加2个新表..

FileStream finschema = new FileStream(schemaPath,FileMode。打开,FileAccess.Rea d,FileShare.Read)

ds.ReadXmlSchema(finschema);

finschema.Close()




System.Strin

System.Strin

System.Strin

System.String //应该有已经是dateTime !!

System.Strin

System.Strin

System.Int3



System.Strin

System.Int3

最后如果我试图休息数据类型我得到这个错误

附加信息:一旦有数据,就无法更改列的数据类型


有什么问题?谢谢Andre


?xml version =" 1.0"编码= QUOT; UTF-8英寸?>< xs:schema xmlns:xs =" http://www.w3.org/2001/XMLSchema" elementFormDefault =" qualified">< xs:element name =" transactionrecord">< xs:complexType>< xs:seque nce>< xs:element ref =" message" />< / xs:sequence>< xs:attribute name =" customercode"类型= QUOT; XS:串QUOT;使用= QUOT;可选" />< xs:attribute name =" model"类型= QUOT; XS:串QUOT;使用= QUOT;可选" />< xs:attribute name =" documentid"类型= QUOT; XS:串QUOT;使用= QUOT;可选" />< xs:attribute name =" transactiondate"类型= QUOT; XS:日期时间"使用= QUOT;可选" />< xs:attribute name =" transactiontype"类型= QUOT; XS:串QUOT;使用= QUOT;可选" />< / xs:complexType>< / xs:element>< xs:element name =" transactions">< xs:complexType>< xs:sequence>< xs:element ref =" transactionrecord" maxOccurs的= QUOT;无界" />< / xs:sequence>< xs:attribute name =" application"类型= QUOT; XS:串QUOT;使用= QUOT;可选" />< / xs:complexType>< / xs:element>< xs:element name =" message">< / xs:element>< / xs:schema>

I read in a earlier post that I can get the column of a grid to sort by datetime if the column type was set as Date

I deserialize my XML and one attribute of the XSD has type as dateTime but upon inspection and behavior in the gri
the data type is string. If I preview the dataset with the GUI in VISSTUDIO it shows my datatype to be dateTime ..

If I try to rest the datatype I get this erro
Additional information: Cannot change DataType of a column once it has data

This adds 2 new tables ..
FileStream finschema= new FileStream(schemaPath,FileMode.Open,FileAccess.Rea d,FileShare.Read)
ds.ReadXmlSchema(finschema);
finschema.Close()

Table
System.Strin
System.Strin
System.Strin
System.String // should have been dateTime !!
System.Strin
System.Strin
System.Int3
Table
System.Strin
System.Int3

Finally if If I try to rest the datatype I get this erro
Additional information: Cannot change DataType of a column once it has data

What''s wrong ??? Thanks Andre

?xml version="1.0" encoding="UTF-8" ?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"><xs:element name="transactionrecord"><xs:complexType><xs:seque nce><xs:element ref="message" /></xs:sequence><xs:attribute name="customercode" type="xs:string" use="optional" /><xs:attribute name="model" type="xs:string" use="optional" /><xs:attribute name="documentid" type="xs:string" use="optional" /><xs:attribute name="transactiondate" type="xs:dateTime" use="optional" /><xs:attribute name="transactiontype" type="xs:string" use="optional" /></xs:complexType></xs:element><xs:element name="transactions"><xs:complexType><xs:sequence>< xs:element ref="transactionrecord" maxOccurs="unbounded" /></xs:sequence><xs:attribute name="application" type="xs:string" use="optional" /></xs:complexType></xs:element><xs:element name="message"></xs:element></xs:schema>

推荐答案

Andrew,


根据我的理解,你想把xml架构文件读入数据集,

有一个datetime列。


如你所说,在读完模式文件之后,你会发现在VS.NET IDE中

调试器, column具有正确的列数据类型:DateTime。但是,什么

做检查和网格中的行为数据类型是字符串

是什么意思?列数据类型视图在哪里是字符串?


我已经测试了你的示例代码片段和xml架构文件,它运行正常。

在调试器中,我可以查看列的数据类型是DateTime。如果我在运行时查看PropertyGrid中的那列
,那么数据类型也是DateTime。


另外,我可以重新设置列的数据自由键入而没有任何问题(它将在运行时反映在PropertyGrid中的
)。像这样:


ds.Tables [0] .Columns [3] .DataType = typeof(Int32);


请澄清我的小信息关于这个问题的问题。


感谢您的耐心与合作。如果您有任何疑问或

担忧,请随时将其发布在小组中。我正准备等待

的帮助。


祝你好运,

Jeffrey Tan

Microsoft在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证也没有授予任何权利。

Hi Andrew,

Based on my understanding, you want to read xml schema file into dataset,
which has a datetime column.

As you said, after read the schema file, you find that in VS.NET IDE
debugger, that column has the correct column data type: DateTime. But, what
does "upon inspection and behavior in the grid the data type is string"
mean? Where does the column data type view is string?

I have tested your sample code snippet and xml schema file, it works fine.
In debugger, I can view that the column''s data type is DateTime. If I view
that column in PropertyGrid at runtime, the data type is also DateTime.

Also, I can re-set the column''s data type freely without any problem(It
will also reflect in PropertyGrid at runtime). Like this:

ds.Tables[0].Columns[3].DataType=typeof(Int32);

Please clarify my little problem about this issue.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


你好Jeff


我说的是当我问VS时STudio预览XSD - 它说数据类型是dateTime - 但是当我实际运行代码时,我得到了字符串 - 我的Console.writeline指示


但你似乎得到了结果非常不同(我希望看到的结果)。所以我会再次回来试试......谢谢
Hi Jeff

What I said was that when I asked VS STudio to preview the XSD - it said the datatype would be dateTime - BUT when I actually ran the code, I was getting string - as my Console.writeline indicated

But you seem to get very different results ( and the results I would like to see ). So I will return again & try... Thanks


安德鲁,


感谢您的反馈。


我将等待您的进一步测试和反馈。谢谢


祝你好运,

Jeffrey Tan

微软在线合作伙伴支持

安全! - www.microsoft.com/security

此帖子按原样提供没有保证,也没有赋予任何权利。

Hi Andrew,

Thanks for your feedback.

I will wait for your further test and feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


这篇关于反序列化为DataSet - DataType?就像虫子一样。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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