I have a SQL2005 XML column I load into a DataSet.
I then bind to a DataGrid.
If I set an asp:Literal text value to the DataSet.GetXml( ) when I first load it into the DataSet, it displays correctly.
If I later try to display the XML content in the asp:Literal control, then I get "<NewDataSe t />". Why is that? Why can't I get the actual XML back from the DataSet? I'm new to DataSets, so I'm probably just missing something basic.
Here's the code... I'm leaving out the ASP.NET markup... if you feel you need to see that too, please let me know.
Basically, I have a text box where the user enters a SQL record #, then they click a button to load it. Then a second button is clicked to display the XML content in the literal control. Currently I also fill the literal with the XML in the first button click for debug purposes.
public partial class SqlXml : System.Web.UI.P age
{
DataSet ds;
protected void Page_Load(objec t sender, EventArgs e)
{
ds = new DataSet();
}
protected void Button1_Click(o bject sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@ "Data Source=.\SQLEXP RESS;Initial Catalog=SqlXmlT est;Integrated Security=True") ;
conn.Open();
string sql = "SELECT [Data] FROM [Record] WHERE ([UserId] = " + tbUserId.Text + ")";
SqlCommand comm = new SqlCommand(sql, conn);
ds.ReadXml(comm .ExecuteXmlRead er());
lit.Text = Server.HtmlEnco de(ds.GetXml()) ;
conn.Close();
DataGrid1.DataS ource = ds;
DataGrid1.DataM ember = "Goal";
DataGrid1.DataB ind();
}
protected void Button2_Click(o bject sender, EventArgs e)
{
lit.Text = Server.HtmlEnco de(ds.GetXml()) ;
}
}
--
Greg Collins [Microsoft MVP]
Visit Braintrove ( http://www.braintrove.com )