Does Dataset.ReadXml() set all columns datatype in its table as string?
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()
Use the following:
DataSet1.ReadXml(stringReader, XmlReadMode.InferTypedSchema);
精彩评论