如何用xml格式表示数据表中的数据。 [英] how to represent data from datatable in xml format.
本文介绍了如何用xml格式表示数据表中的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据表中有一个数据,我想要xml格式。我不知道从哪里开始。任何帮助都是appreaciated.Below是我从我的datatable获取数据的代码。请帮我一些良好的链接或建议。
string querystring = Request.QueryString [Userid];
DataTable dtfrnameid = new DataTable();
connfordata.Open();
SqlCommand cmdfrnameid = new SqlCommand(从s000_users中选择s000_UserId,其中(s000_firstname + s000_lastname)='+ querystring +',connfordata);
SqlDataAdapter dafrnameid = new SqlDataAdapter(cmdfrnameid);
dafrnameid.Fill(dtfrnameid);
connfordata.Close();
string id = dtfrnameid.Rows [0] [0] .ToString();
lblfrogridview.Text =;
string weekendnding = gvweeklysum.Rows [rindex] .Cells [1] .Text;
DateTime getweekending = Convert.ToDateTime(周末);
DateTime dtmonday = getweekending.AddDays(-4);
DateTime castdttime = dtmonday.AddHours(12);
var monday = castdttime.Date.ToString(yyyy-MM-dd 12:mm:ss);
DataTable dtfrmonday = new DataTable();
connfordata.Open();
SqlCommand cmdfrmonday = new SqlCommand(SRTSWeeklySummaryWednesday,connfordata);
SqlDataAdapter dafrmonday = new SqlDataAdapter(cmdfrmonday);
cmdfrmonday.CommandType = CommandType.StoredProcedure;
cmdfrmonday.Parameters.Add(new SqlParameter(@ createddate,SqlDbType.DateTime))。Value = monday;
cmdfrmonday.Parameters.Add(new SqlParameter(@ userid,SqlDbType.Int))。Value = id;
dafrmonday.Fill(dtfrmonday);
connfordata.Close();
解决方案
尝试WriteXml方法
/ * 将数据表导出到xml * /
dtfrmonday.TableName = < span class =code-string> MyTable;
dtfrmonday.WriteXml( Path \FileName.xml,XmlWriteMode.WriteSchema);
/ * 将xml导入datatable * /
dtfrmonday。 TableName = MyTable;
dtfrmonday.ReadXml( Path \FileName.xml);
我建议你看看XML类。您需要自己完成大部分工作,但是一旦获得数据,只需编写XML文件即可。
点击此处 [ ^ ]获取有关创建XML的简单教程。
查看此链接:
DataTable.WriteXml方法 [ ^ ]
希望它有所帮助! :)
I have a data in my datatable which i want in xml format.I have no idea where to start with.Any help is appreaciated.Below is the code where i get the data from my datatable.Please help me out with some good links or suggestions.
string querystring = Request.QueryString["Userid"]; DataTable dtfrnameid = new DataTable(); connfordata.Open(); SqlCommand cmdfrnameid = new SqlCommand("select s000_UserId from s000_users where (s000_firstname+s000_lastname) = '" + querystring + "'", connfordata); SqlDataAdapter dafrnameid = new SqlDataAdapter(cmdfrnameid); dafrnameid.Fill(dtfrnameid); connfordata.Close(); string id = dtfrnameid.Rows[0][0].ToString(); lblfrogridview.Text = ""; string weekending = gvweeklysum.Rows[rindex].Cells[1].Text; DateTime getweekending = Convert.ToDateTime(weekending); DateTime dtmonday = getweekending.AddDays(-4); DateTime castdttime = dtmonday.AddHours(12); var monday = castdttime.Date.ToString("yyyy-MM-dd 12:mm:ss"); DataTable dtfrmonday = new DataTable(); connfordata.Open(); SqlCommand cmdfrmonday = new SqlCommand("SRTSWeeklySummaryWednesday", connfordata); SqlDataAdapter dafrmonday = new SqlDataAdapter(cmdfrmonday); cmdfrmonday.CommandType = CommandType.StoredProcedure; cmdfrmonday.Parameters.Add(new SqlParameter("@createddate", SqlDbType.DateTime)).Value = monday; cmdfrmonday.Parameters.Add(new SqlParameter("@userid", SqlDbType.Int)).Value = id; dafrmonday.Fill(dtfrmonday); connfordata.Close();
解决方案
try WriteXml Method
/*Export datatable to xml */ dtfrmonday.TableName = "MyTable"; dtfrmonday.WriteXml("Path\FileName.xml", XmlWriteMode.WriteSchema); /*Import xml to datatable */ dtfrmonday.TableName = "MyTable"; dtfrmonday.ReadXml("Path\FileName.xml");
I suggest you take a look at the XML classes. You will need to do most of it yourself but once you have the data it is just a matter of writing the XML file.
Click Here[^] for a good simple tutorial on creating an XML once you have the data.
See this link:
DataTable.WriteXml Method[^]
Hope it helps! :)
这篇关于如何用xml格式表示数据表中的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文