问题描述
亲爱的,
这是我的代码。
i可以创建xml文件。
但它只写最后一行值。
不写所有行。
public void drtoXML ()
{
SqlConnection Conn = new SqlConnection(Data Source =; Initial Catalog = Employee;);
string sqlText =从EMP FOR XML AUTO中选择*;
SqlCommand dataCmd = new SqlCommand(sqlText,Conn);
XmlWriter writer = null;
Conn .Open();
XmlReader dataReader = dataCmd.ExecuteXmlReader();
while(dataReader.Read())
{
使用(writer = XmlWriter.Create(@D:\ Manas \Prod.xml))
{
writer.WriteNode(dataReader) ,true);
}
}
dataReader.C lost();
Conn.Close();
}
请帮帮我。
dear all,
here is my code.
i can able to create the xml file.
but it is writing only last row value .
not writing all the rows.
public void drtoXML()
{
SqlConnection Conn = new SqlConnection("Data Source=;Initial Catalog=Employee;");
string sqlText = "select * from EMP FOR XML AUTO";
SqlCommand dataCmd = new SqlCommand(sqlText, Conn);
XmlWriter writer = null;
Conn.Open();
XmlReader dataReader = dataCmd.ExecuteXmlReader();
while (dataReader.Read())
{
using (writer = XmlWriter.Create(@"D:\Manas\Prod.xml"))
{
writer.WriteNode(dataReader, true);
}
}
dataReader.Close();
Conn.Close();
}
please help me.
推荐答案
public void drtoXML()
{
SqlConnection Conn = new SqlConnection("Data Source=;Initial Catalog=Employee;");
string sqlText = "select * from EMP FOR XML AUTO";
SqlCommand dataCmd = new SqlCommand(sqlText, Conn);
XmlWriter writer = null;
Conn.Open();
XmlReader dataReader = dataCmd.ExecuteXmlReader();
using (writer = XmlWriter.Create(@"D:\Manas\Prod.xml"))
{
while (dataReader.Read())
{
writer.WriteNode(dataReader, true);
}
}
dataReader.Close();
Conn.Close();
}
这篇关于使用c3中的datareader创建xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!