本文介绍了难道Dataset.ReadXml()设置在其作为字符串表中的所有列的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是code从Web服务获取XML数据,然后将数据集读取使用ReadXml方法。这个XML有ID和指明MyDate标签为每个表行(所以表(0)将有ID和指明MyDate列)和XML数据不具有与它相关联的模式。当网页加载它第一次在递增顺序排序按ID。这是工作,直到编号为999。如果下一个ID之际,1000年,即使是在ID递增,1000在数据网格999之前显示。

我想确认时,数据集的ReadXml使用加载在其表中的所有列,即使它们是数字或日期视为字符串,这就是为什么在ID ASC为了1000 999之前来了。

此外,指明MyDate标签有日期,格式为2011年1月31日(MM / DD / YYYY),似乎排序wroking罚款的日期。会按日期排序总是工作,即使数据集表指明MyDate列类型的字符串(假设我的上述说法是正确的)?

是我的上述两个假设是否正确?

 流=新System.IO.StringReader(从Web服务返回的XML数据)
  随着数据集
  .ReadXml(流)
  dvView = .Tables(0).DefaultView
  dvView.Sort =ID ASC'ID是数
  随着** **数据网格是的DataGrid
        .DataSource = dvView
        .DataKeyField =ID这是数
        .DataBind()
 

解决方案

使用以下内容:

  DataSet1.ReadXml(stringReader,XmlReadMode.InferTypedSchema);
 

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);

这篇关于难道Dataset.ReadXml()设置在其作为字符串表中的所有列的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 22:38