I have a dataset. I get the XML rapresentation of that data with the method GetXML. Now i want to put it back to the dataset. How can I do? I know how to do this with an XML file...
Thx,
Xmas
Printable View
I have a dataset. I get the XML rapresentation of that data with the method GetXML. Now i want to put it back to the dataset. How can I do? I know how to do this with an XML file...
Thx,
Xmas
sorry:D , but do you want to write from dataset or to dataset , :confused: ?Quote:
Originally posted by Xmas79
I have a dataset. I get the XML rapresentation of that data with the method GetXML. Now i want to put it back to the dataset. How can I do? I know how to do this with an XML file...
Thx,
Xmas
I want to fill a dataset. I know how to fill dataset starting from an XML file, but I want to know how to fill dataset starting from an XML string.
VB Code:
'after open connection and stuff do this ... Dim ds As New DataSet() Dim xmlstr As String xmlstr = ds.GetXml()
I know this!!!!!! I want to do the reverse!!!!!!
Is it this the reverse you're talking about ?:confused:VB Code:
Dim ds As New DataSet() ds.ReadXml("....\myxml.xml")
No, it's like this:VB Code:
Dim ds As New DataSet() Dim xmlstr As String ds.ReadXml(xmstr)
This is what you said before. I don't want this. It's similar, but I want to fill a dataset from an XML string, not from an XML file.Quote:
Originally posted by pirate
It's commented.....Quote:
Originally posted by Xmas79
This is what you said before. I don't want this. It's similar, but I want to fill a dataset from an XML string, not from an XML file.
from the downloaded file:VB Code:
Public ds As New DataSet() Public str As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '***** 1ST PART ***** 'fill data from XML File ds.ReadXml("xml1.xml") '***** END 1ST PART ***** '***** 2ND PART ***** Dim dr As DataRow = ds.Tables(0).Rows(0) 'write XML content to textbox (you can store it to string 'variable type) TextBox1.Text = dr.Item(0) '***** END 2ND PART ***** '***** 3RD PART ***** 'this will store string value to dataset again Dim dasave As DataRow = ds.Tables(0).NewRow() dasave(0) = TextBox1.Text ds.Tables(0).Rows.Add(dasave) '***** END 3RD PART ***** End Sub
1ST PART: Fill a DataSet reading from file. Not what I want.
2ND PART: Takes a row from an already filled DataSet and put it into a textbox. Not what I want.
3RD PART: Put back the textbox.text into an already structured, well formed DataSet. Not what I want.
WHAT I WANT: Fill a new empty DataSet from a String. It means that I have a string that IS a dataset in XML form. I could save it to a file, and then read it with the 1ST PART method. But I don't want to save to file! Clear?
this will do the job . either you're not understanding the post or the question :Quote:
Originally posted by Xmas79
from the downloaded file:VB Code:
Public ds As New DataSet() Public str As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '***** 1ST PART ***** 'fill data from XML File ds.ReadXml("xml1.xml") '***** END 1ST PART ***** '***** 2ND PART ***** Dim dr As DataRow = ds.Tables(0).Rows(0) 'write XML content to textbox (you can store it to string 'variable type) TextBox1.Text = dr.Item(0) '***** END 2ND PART ***** '***** 3RD PART ***** 'this will store string value to dataset again Dim dasave As DataRow = ds.Tables(0).NewRow() dasave(0) = TextBox1.Text ds.Tables(0).Rows.Add(dasave) '***** END 3RD PART ***** End Sub
1ST PART: Fill a DataSet reading from file. Not what I want.
2ND PART: Takes a row from an already filled DataSet and put it into a textbox. Not what I want.
3RD PART: Put back the textbox.text into an already structured, well formed DataSet. Not what I want.
WHAT I WANT: Fill a new empty DataSet from a String. It means that I have a string that IS a dataset in XML form. I could save it to a file, and then read it with the 1ST PART method. But I don't want to save to file! Clear?
VB Code:
Dim dr_save As DataRow = new_ds.Tables(0).NewRow() Dim mystr = "blah blah" dr_save(0) = mystr ds.Tables(0).Rows.Add(dr_save)
To load xml as a string you can either use a derived XMlReader (i.e the XMLTextReader object) which for your situation may be more than is needed. You can also load the string into a memorystream and load it from there. Here is an example of the later:
VB Code:
'syntax example dim ds as Dataset=FillDatasetWithXML(myXMLString) Public Function FillDatasetWithXML(ByVal xml As String) As DataSet Dim ds As New DataSet() Dim ms As New IO.MemoryStream() Dim sw As New IO.StreamWriter(ms) 'write cml to the stream sw.Write(xml) sw.Flush() 'position to the start of the stream ms.Position = 0 'read the xml in to the dataset ds.ReadXml(ms) 'clean up sw.Close() ms.Close() Return ds End Function
pirate: This will not do the job!!! Your code puts into a field of the DataSet the value contained in my string, but this isn't what I want! I want to get both structure and fields values of the DataSet from the string.
Edneeis: This will do the job. I did it in the same way, but I used StringReader (I think... I'm too tired to remember, and I can't see the code because I've to reboot...) instead of memorystream...
Thx you both,
Xmas