可以将数据库里的数据导到xml文档里吗?
怎么将数据库里的数据导到xml里呀,使这些数据生成一份xml文档,没做过,请教了! 问题点数:20、回复次数:1Top
1 楼yystudent(学生)回复于 2006-03-01 14:59:57 得分 0
前不久用c#做过xml数据导入导出,不知能否满足你的要求,代码大致如下:
//生成xml数据
sqlConnection1.Open();
sqlCommand1=new SqlCommand("select aa from a3",sqlConnection1);
SqlDataAdapter adapter1=new SqlDataAdapter();
adapter1.SelectCommand=sqlCommand1;
DataSet data1=new DataSet();
adapter1.Fill(data1,"a3");
sqlConnection1.Close();
using(FileStream fd = File.Create("c:\\vcnet\\test3.xml"))
{Byte[] info = new UTF8Encoding(true).GetBytes("");
fd.Write(info, 0, info.Length);
}
System.IO.FileStream fs=new System.IO.FileStream"c:\\vcnet\\test3.xml",System.IO.FileMode.Create);
try
{
data1.WriteXml(fs, XmlWriteMode.WriteSchema);
MessageBox.Show("生成文件");
}
catch(Exception er)
{
MessageBox.Show(er.Message);
}
fs.Close(); Top




