PDA

View Full Version : خروجی XML از دیتاست



raminchala66
شنبه 20 تیر 1388, 10:27 صبح
public static void Export_XML(string PathName,string CommandText)
{
MessageBox.Show(PathName);
SqlConnection con = new SqlConnection(Form1.ConnStr);
SqlCommand command = new SqlCommand();
command.CommandText = CommandText;
command.CommandType = CommandType.Text;
command.Connection = con;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds, "tbname");

// Get a StreamWriter object
//StreamWriter xmlDoc = new StreamWriter(PathName,false);
FileStream xmlDoc = new FileStream(PathName, FileMode.Create);
// Apply the WriteXml method to write an XML document
ds.WriteXml(xmlDoc);
xmlDoc.Flush();
xmlDoc.Close();

}



این کد من اجرا میشه یه فایله xml مسازه وقتی فایل میخوام باز کنم میگه :


XML document must have a top level element

کمک کنید لطفا

raminchala66
شنبه 20 تیر 1388, 13:20 عصر
مشکل از savedialog بود کد بالا کاملا درسته