בקשת עזרה .Net & MSSQL

MrProg

New member
בקשת עזרה .Net & MSSQL

שלום לכולם אשמח עם אוכל לקבל עזרה אני מנסה לקבל תוצאות שאילתה של MSSQL לתוך XMLReader באמצעות המתודה SqlCommand.ExecuteSQLReader, לאחר שאני מנסה להעביר את הנתונים לתוך XmlDocument אני מקבל הודעת שגיאה
This document already has a DocumentElement node.​
מצורף הקוד הרלוונטי במלואו
System.Data.SqlClient.SqlCommand Cmd = new SqlCommand("Select * From Orders FOR XML AUTO", GetConnection()); Cmd.Connection.Open(); try { System.Xml.XmlDocument Doc = new System.Xml.XmlDocument(); Doc.Load(Cmd.ExecuteXmlReader()); context.Response.ContentType = "Text/XML"; Doc.Save(context.Response.OutputStream); context.Response.End(); } finally { Cmd.Connection.Close(); }​
תודה רבה
 

MrProg

New member
Exception

אני מקבל את ה-Exception בעת נסיון לבצע את
Doc.Load(Cmd.ExecuteXmlReader());​
 

gooshi

New member
XmlReader

System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand("Select * From Orders FOR XML AUTO", GetConnection()); Cmd.Connection.Open(); try { System.Xml.XmlDocument Doc= new System.Xml.XmlDocument(); System.Xml.XmlReader read; read=Cmd.ExecuteXmlReader(); read.MoveToContent(); Doc.LoadXml(read.ReadOuterXml()); HttpContext.Current.Response.ContentType = "Text/XML"; Doc.Save(HttpContext.Current.Response.OutputStream); HttpContext.Current.Response.End(); } finally { Cmd.Connection.Close(); //very importnat: read.Close(); }
 

yuval k

New member
למה לא ליישר לשמאל? ../images/Emo4.gif

System.Data.SqlClient.SqlCommand Cmd = new System.Data.SqlClient.SqlCommand("Select * From Orders FOR XML AUTO", GetConnection()); Cmd.Connection.Open(); try { System.Xml.XmlDocument Doc= new System.Xml.XmlDocument(); System.Xml.XmlReader read; read=Cmd.ExecuteXmlReader(); read.MoveToContent(); Doc.LoadXml(read.ReadOuterXml()); HttpContext.Current.Response.ContentType = "Text/XML"; Doc.Save(HttpContext.Current.Response.OutputStream); HttpContext.Current.Response.End(); } finally { Cmd.Connection.Close(); //very importnat: read.Close(); }​
 
למעלה