asp.net怎么把dataset序列化成xml不用输出xml文件只要一个xml格式的数据集就可以
2个回答
展开全部
方法一:
string sqlMsg = "SELECT TOP 3 f.WorkNo,f.Title,f.DepartmentId FROM dbo.frmuser";
//返回DataTable
System.Data.DataTable table = SqlHelper.ExecuteDataTable(sqlMsg);
table.TableName="frmuser";
System.IO.TextWriter writer = new System.IO.StringWriter();
table.WriteXml(writer);
string xml = writer.ToString();
//xml结果如下:
<DocumentElement>
<frmuser>
<WorkNo>LSZ00241</WorkNo>
<Title>职员</Title>
<DepartmentId>34</DepartmentId>
</frmuser>
<frmuser>
<WorkNo>LSZ00263</WorkNo>
<Title>职员</Title>
<DepartmentId>34</DepartmentId>
</frmuser>
<frmuser>
<WorkNo>LSZ00236</WorkNo>
<Title>职员</Title>
<DepartmentId>34</DepartmentId>
</frmuser>
</DocumentElement>
方法二:
//返回DataSet
System.Data.DataSet set = SqlHelper.ExecuteDataset(sqlMsg);
string xml2 = set.GetXml();
//xml2结果同上
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询