请问如何把SQLSERVER中一个表中数据转换到XML文件中?

cutman 2004-08-11 07:58:45
同上
...全文
190 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cutman 2004-08-11
  • 打赏
  • 举报
回复
搞定了,谢谢2位
cutman 2004-08-11
  • 打赏
  • 举报
回复
谢谢楼上2位,我这样写:

string strCon = "Integrated Security=SSPI;Server=(local);Database=Test";
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
string sql = "SELECT * FROM Field";
SqlCommand Cmd = new SqlCommand(sql,conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(Cmd);
da.Fill(ds);
ds.GetXml();
string filename = "test.xml";
FileStream fs = new FileStream(filename,FileMode.Create);
XmlTextWriter writer = new XmlTextWriter(fs, System.Text.Encoding.Unicode);
ds.WriteXml(writer);

出错:对路径“c:\windows\system32\inetsrv\test.xml”的访问被拒绝。
WHY?
孟子E章 2004-08-11
  • 打赏
  • 举报
回复
http://dotnet.aspx.cc/ShowDetail.aspx?id=F3EB8683-DB3C-4460-ADB7-7C5C12348A11
八爪鱼-杭州 2004-08-11
  • 打赏
  • 举报
回复
把表中的数据select出来fill到dataset,再用dataset.getxml()就可以得到xml字符串了,然后再写到文件中去
或者用
select * from table for xml
来得到表的xml字符串再写到文件中去
cutman 2004-08-11
  • 打赏
  • 举报
回复
up 急

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧