By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 2,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Editable SQL05 XML in ASP.NET

P: n/a
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(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=SqlXmlTest;Integrated Security=True");
conn.Open();

string sql = "SELECT [Data] FROM [Record] WHERE ([UserId] = " + tbUserId.Text + ")";
SqlCommand comm = new SqlCommand(sql, conn);
XmlReader reader = comm.ExecuteXmlReader();
XmlDocument doc = new XmlDocument();
doc.Load(reader);

reader.Close();
conn.Close();

XmlDataSource1.Data = doc.OuterXml;
Repeater1.DataSourceID = "XmlDataSource1";
}

protected void Button2_Click(object 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 )
Apr 26 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.