473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Editable SQL05 XML in ASP.NET

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)?

--
Greg Collins [Microsoft MVP]
Visit Braintrove ( http://www.braintrove.com )
Apr 25 '07 #1
5 1229
Hi Greg, I never did that before, but have you tried to put the xml in a
XmlDocument class?

Bruno

"Greg Collins [Microsoft MVP]" <gcollins_AT_ms n_DOT_comwrote in message
news:uJ******** ******@TK2MSFTN GP03.phx.gbl...
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)?

--
Greg Collins [Microsoft MVP]
Visit Braintrove ( http://www.braintrove.com )

Apr 26 '07 #2
Yes, I pull the SQL XML column down and place it in an XmlDocument, and then I put 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 )
Apr 26 '07 #3
Hi greg,
according to the documentation, the XmlDataSource control is tipically used
on read-only scenarios. My suggestion would be to load the xml into a
dataset (assuming you can change the xml accordingly if needed), this will
create a datatable filled in the dataset, then you use this datatable as the
datasource of a gridview for example...

what you think?

Bruno

"Greg Collins [Microsoft MVP]" <gcollins_AT_ms n_DOT_comwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
Yes, I pull the SQL XML column down and place it in an XmlDocument, and then
I put 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 )

Apr 26 '07 #4
I'm still fairly new to a lot of this. I have XML/XSLT/HTML background, and I've got my feet wet in ASP.NET and SQL -- but a lot of these asp:controls are still new to my. Still trying to wrap my head around them as quickly as possible.

How complex of an XML structure can a dataset handle? If not very, maybe I can do multiple datasets and pull various parts of the document out... I'd have to see if that would work.

I'm assuming it's fairly easy to drop an XML doc into a dataset? Do you have a small code sample or a pointer to an article?

Thanks!

--
Greg Collins [Microsoft MVP]
Visit Braintrove ( http://www.braintrove.com )
Apr 27 '07 #5
Hi Greg,
The underlying data of a DataSet is stored as XML.

Below is a code that creates a DataSet, a DataTable, DataColumns and then
add some sample data.

protected void Button1_Click(o bject sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("MyDa taTable");

dt.Columns.Add( new DataColumn("ID" , typeof(Int32))) ;
dt.Columns.Add( new DataColumn("Nam e", typeof(string)) );

ds.Tables.Add(d t);

dt.Rows.Add(new object[] { 1, "Bruno 1" }); /* the values passed
here are in the order of creation of the datacolumns, "ID" first, "Name"
second */
dt.Rows.Add(new object[] { 2, "Bruno 2" });
dt.Rows.Add(new object[] { 3, "Bruno 3" });

Response.Write( "<pre>" + Server.HtmlEnco de(ds.GetXml()) + "</pre>");
}

The GetXml method returns the underlying xml... this is to show you how the
xml structure is, and below is a code that you would use to "bind" this xml
to a GridView control.

protected void Button2_Click(o bject sender, EventArgs e)
{
DataSet ds = new DataSet();

/* fills the dataset with the xml from db */
ds.ReadXml(comm and.ExecuteXmlR eader());

GridView1.DataS ource = ds.Tables[0];
GridView1.DataB ind();
}

I don't know how the scructure of your xml is, but if you can fit it in a
DataSet it would be a good way to do what you want, try to add more
DataTables to the DataSet and see the output xml. Check also the
GetXmlSchema and ReadXmlSchema methods of the DataSet.

More info on DataSet here
http://msdn2.microsoft.com/en-us/lib...a.dataset.aspx

Bruno
Apr 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2157
by: ANC | last post by:
hi, i would like to ask how can i set a field of recordset to be editable? thanks in advance. ANC
17
3854
by: black tractor | last post by:
HI there.. l was just wondering, if l place a "table" in the "editable region" of my template, will the text, graphics placed inside the this "table" MOVE BY ITSELF?? l mean, recently l had a "table" insert in my "editable region", have it placed in the "center" of the page.. while it display correctly on my browser, with setting at 1024x768 (IE6),
7
9332
by: deko | last post by:
SELECT tblTxAcct.TxAcctName, tblTxType.TxTypeName, Nz(qryTxAcctListCt.TxCount, 0) AS TxCt FROM (tblTxAcct INNER JOIN tblTxType ON tblTxAcct.TxType_ID=tblTxType.TxType_ID) LEFT JOIN qryTxAcctListCt ON tblTxAcct.TxAcct_ID=qryTxAcctListCt.TxAcct_ID; I use this query as a RecordSource for a Datasheet that displays Accounts, Types, and the number of Transactions in each Account. An Account cannot exist outside of a Type, but an Account...
4
1792
by: Stephan Bour | last post by:
Hi, I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns when the Edit button is pressed? Thank you, Stephan.
6
10662
by: Hako | last post by:
Hello All, I have a function to set readonly or editable of a textctrl. I'd like to make the textctrl initial set readonly and use other event funciton to set editable of the textctrl but it always can editable. How to set a textctrl can editable or readonly? Any Ideas? (see short snippet below) Thanks.
1
1064
by: John Bailo | last post by:
I just installed c# express and sql05 express. I don't see a query tool in the start menu -- but it says there is one installed in add/remove programs. Is there a "query analyzer" that comes with sql05expr ?
0
1964
by: Greg Collins [Microsoft MVP] | last post by:
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...
0
3485
by: muchinger | last post by:
All, I create 2 combo boxes on a page: an editable one and a non-editable one. Both of them have the same string items which are too long to entirely fit into the combo box. E. g. the size of the combo boxes is just large enough to display the half of the string "one word". Now when selecting the item "one word" in both combo boxes, the editable combo box would show "word" while the non-editable combo box would show "one ". I would...
2
3051
by: sahista | last post by:
Hello. I create an iframe on the fly, set it to editable designMode='on' and insert into iframe.contentWindow.childNodes.childNodes some innerHTML. Ok... that all works fine in IE but in firefox it wont became editable neither insert the innerHTML!? I tried also set the onreadystatechange on iframe to for making it editable and set the innerHTML into contentWindow..nothing... any suggestion appreciated!
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.