利用sqlhelper中的ExcuteXmlReader方法,读取数据并保存为xml文件
string strConn = Properties.Settings.Default.Connections;
SqlConnection connection = new SqlConnection(strConn);
---注意:后面的for格式
string strsql = "select * from p where name=@name and other=@other FOR XML AUTO,root('root'),elements";
SqlParameter[] sqlp = new SqlParameter[2];
sqlp[0] = new SqlParameter("@name", "pp");
sqlp[1] = new SqlParameter("@other", "ss");
xr = SqlHelper.ExecuteXmlReader(connection, CommandType.Text, strsql,
sqlp);
XmlDocument xml = new XmlDocument();
xml.Load(xr);
xml.Save(Application.StartupPath + "//test1.xml");