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...
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
sorry , but do you want to write from dataset or to dataset , ?
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.
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?
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?
this will do the job . either you're not understanding the post or the question :
VB Code:
Dim dr_save As DataRow = new_ds.Tables(0).NewRow()
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
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...