如何从XML填充数据集 [英] How can i Fill dataset from XML
问题描述
我有以下给出的xml数据
我正在尝试从xml字符串而不是xml文件填充数据集,我想将上述xml转换为datset/datatable
I have xml data as given bellow
i am trying to fill dataset from xml string not xml file and i want to convert above xml to datset / datatable
<reportdata>
<columns day="Thrusday" date="12/1/2011 12:00:00 AM">
<column name="cDATA" calculated="0" formula="" value="1" />
<column name="dDATA" calculated="0" formula="" value="5" />
<column name="Total_DS" calculated="1" formula="cDATA+dDATA" value="6" />
</columns>
<columns day="Friday" date="12/2/2011 12:00:00 AM">
<column name="cDATA" calculated="0" formula="" value="2" />
<column name="dDATA" calculated="0" formula="" value="4" />
<column name="Total_DS" calculated="1" formula="cDATA+dDATA" value="6" />
</columns> </reportdata>
我正在尝试从xml上方填充数据集并将数据集分配给datagridview
I am trying to fill dataset from above xml and assign dataset to datagridview
BLL.Dailydrawer oBO = new BLL.Dailydrawer();
DataTable DTPrevMonth = oBO.FillPreviousMonths();
DataRow[] DR = DTPrevMonth.Select(string.Format("MonthId = {0}", PrevMonthId));
string XML = Convert.ToString(DR[0]["DataXML"]);
DataSet DS = new DataSet();
System.IO.StringReader xmlSR = new System.IO.StringReader(XML);
DS.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);
但数据集什么也不显示.
but dataset display nothing.
Please help me urgent how can i do this?
推荐答案
DS.ReadXml(mappath("file.xml"));
假设您使用的是Winforms,
Assuming you are working in winforms,
DataSet ds = new DataSet();
ds.ReadXml(Application.StartupPath.Replace("\\bin\\Debug","")+"\\XMLFile1.xml");
如果xml文件位于根文件夹中,则它将在数据集中加载xml文件.
this will load the xml file in dataset, if the xml file is in the root folder..
尝试
DataSet ds = new DataSet();
ds.ReadXml(@"YourXML FIle");
或
参考链接:-使用XML中的数据填充数据集 [
or
Reference Link :- Fill DataSet with the data from XML[^]
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml("Your XML File");
DataSet ds = new DataSet("DatSet Name");
ds = xmlDatadoc.DataSet;
参考链接:-将XML加载到数据集 [
Reference Link :- Load XML to DataSet[^]
这篇关于如何从XML填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!