XML to DataSet

  • Thread starter Thread starter SDF
  • Start date Start date
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
 
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()?
 
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
 
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.
 
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
 
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!
 
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
 
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
 
Cecil,

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

Scott
 
I got it:

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

sw.ToString 'returns the XML contents as a string


Scott
 
Back
Top