Does Dataset.ReadXml() set all columns datatype in its table as string?

China☆狼群 提交于 2019-12-24 02:33:21

问题


Following is the code which gets xml data from web service and then dataset reads using ReadXml method. This Xml has ID and MyDate tags for each table row (so table(0) will have ID and MyDate columns) and this Xml data does not have schema associated with it. When page is loaded first time, it sorts by ID in asc order. It was working until ID was 999. When next ID came as 1000, even in ID asc, 1000 is showing before 999 in datagrid.

I wanted to confirm that when dataset is loaded using ReadXml, all the columns in its table are treated as string even they are numbers or dates and that's why in ID asc order 1000 is coming before 999.

Also, MyDate tag has date in format "01/31/2011" (mm/dd/yyyy) and it seems that sorting is wroking fine for date. Would sorting by date always work even when dataset table MyDate column is of type string (assuming that my above statement is correct)?

Are my two above assumptions correct?

 stream = New System.IO.StringReader(XML data returned from web service)
  With dataset
  .ReadXml(stream)
  dvView = .Tables(0).DefaultView
  dvView.Sort = "ID asc" 'ID is number
  With **datagrid** 'it is DataGrid
        .DataSource = dvView 
        .DataKeyField = "ID" 'this is number
        .DataBind()  

回答1:


Use the following:

DataSet1.ReadXml(stringReader, XmlReadMode.InferTypedSchema);


来源:https://stackoverflow.com/questions/7041036/does-dataset-readxml-set-all-columns-datatype-in-its-table-as-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!