What do people use when they want to pull XML from a SQL05 XML datatype column, edit it in an ASP.NET web app, and the post the updated XML back to SQL05?
I've looked into pulling the XML down into an XmlDataSource control, but this doesn't seem to be a very likely option as the bindings are readonly.
Seems like a common enough scenario--what have you done (those who have done this)?
I've tried pulling the SQL XML column down and place it in an XmlDocument, and then puting that into an XmlDataSource, but then I can't read it back out from there...
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);
XmlReader reader = comm.ExecuteXml Reader();
XmlDocument doc = new XmlDocument();
doc.Load(reader );
reader.Close();
conn.Close();
XmlDataSource1. Data = doc.OuterXml;
Repeater1.DataS ourceID = "XmlDataSource1 ";
}
protected void Button2_Click(o bject sender, EventArgs e)
{
string sql = "UPDATE [Record] SET [Data] = '" + XmlDataSource1. Data +"' WHERE ([UserId] = " + tbUserId.Text + ")";
Response.Write( sql);
}
The Button1 click works fine... but clicking Button2, XmlDataSource1. Data (which is supposed to be read/write) gives me an empty string.
In the web page, I bound the data to a text box control, so I could try editing it to see what would happen... but I just get a blank trying to read the Data property no matter what.
Ideas?
--
Greg Collins [Microsoft MVP]
Visit Braintrove ( http://www.braintrove.com )