XML to DataSet

S

SDF

Hi all,

I have a SQL2000 table where one field is text and contains an XML document.
What I need to do is query the row and take the contents of the XML field
and create a DataSet from it. That DataSet will then be bound to a control.
Updates can be made and then I need to convert the Dataset back to XML and
update the field in the DB. Somehow I am stumbling on this and wasting
time - I've looked at XMLDataDocument and StreamReader but I can't seem to
load the string field value into one of these.

Does anyone have any suggestions or direction for me?

Thanks In Advance,

Scott
 
F

Fabio

SDF said:
I have a SQL2000 table where one field is text and contains an XML document.
What I need to do is query the row and take the contents of the XML field
and create a DataSet from it. That DataSet will then be bound to a control.
Updates can be made and then I need to convert the Dataset back to XML and
update the field in the DB. Somehow I am stumbling on this and wasting
time - I've looked at XMLDataDocument and StreamReader but I can't seem to
load the string field value into one of these.

Does anyone have any suggestions or direction for me?

Have you already tried XmlDataDocument.LoadXml()?
 
S

SDF

Fabio,

yes I tried that - I tried to pass a string containing the XML contents:

Dim xmlDataDoc As New XmlDataDocument(dsXML)

xmlDataDoc.LoadXml(sqlDS.Tables(0).Rows(0).Item(1))



But dsXML.Tables.Count = 0



Scott

Fabio said:
SDF said:
I have a SQL2000 table where one field is text and contains an XML document.
What I need to do is query the row and take the contents of the XML field
and create a DataSet from it. That DataSet will then be bound to a control.
Updates can be made and then I need to convert the Dataset back to XML and
update the field in the DB. Somehow I am stumbling on this and wasting
time - I've looked at XMLDataDocument and StreamReader but I can't seem to
load the string field value into one of these.

Does anyone have any suggestions or direction for me?

Have you already tried XmlDataDocument.LoadXml()?

--
Software is like sex: it's better when it's free -- [Linus Torvalds]

Fabio Marini - A+, RHCT, MCDBA, MCAD.NET
To reply: news [at] mamakin1976 [dot] plus [dot] com
 
R

Robbe Morris - Microsoft MVP C#

I've had this happen. I can't find the specific documentation for it but
I've found that if the string is too long, .NET breaks the results up into
multiple results. Try using a StringBuilder, iterate through the DataRows
appending each row to the string builder. Then, us the .ToString() method
as the input parameter of your XmlDocument.
 
C

cecil

Scott,
You can try the Datasets ReadXml method and pass it a StringReader
that was passed your xml string in it's constructor as follows:

string s ="<XML Text>";
System.IO.StringReader reader = new System.IO.StringReader(s);
cust.ReadXml(reader);

To reverse the process use StringWriter and Datasets WriteXml method.

This assumes of course that the xml in the database has a suitable
schema to be read into a Dataset.

Cecil Howell MCSD, MCT
 
S

SDF

Cecil,

Thank you so much for the suggestion as it worked well!

Scott

cecil said:
Scott,
You can try the Datasets ReadXml method and pass it a StringReader
that was passed your xml string in it's constructor as follows:

string s ="<XML Text>";
System.IO.StringReader reader = new System.IO.StringReader(s);
cust.ReadXml(reader);

To reverse the process use StringWriter and Datasets WriteXml method.

This assumes of course that the xml in the database has a suitable
schema to be read into a Dataset.

Cecil, thanks for the suggestion, I got much closer but the results is a
table without any rows!
 
S

SDF

Robbe,

Thank you for the information - Cecil's suggestion below worked well but I
will keep in mind the information regarding large XML datasets.

Scott
 
M

Michael McGaha

I thought LoadXml loaded a file... LoadXmlString loads a string.

but I may be wrong. I'm going from memory.

Michael

SDF said:
Fabio,

yes I tried that - I tried to pass a string containing the XML contents:

Dim xmlDataDoc As New XmlDataDocument(dsXML)

xmlDataDoc.LoadXml(sqlDS.Tables(0).Rows(0).Item(1))



But dsXML.Tables.Count = 0



Scott

seem
to
load the string field value into one of these.

Does anyone have any suggestions or direction for me?

Have you already tried XmlDataDocument.LoadXml()?

--
Software is like sex: it's better when it's free -- [Linus Torvalds]

Fabio Marini - A+, RHCT, MCDBA, MCAD.NET
To reply: news [at] mamakin1976 [dot] plus [dot] com
 
S

SDF

Cecil,

I am stuck on how to get the xml back into the database. You happen to have
sample using StringWriter?

Scott
 
S

SDF

I got it:

dim sw as New System.IO.StringWriter
ds.WriteXML(sw)

sw.ToString 'returns the XML contents as a string


Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top