By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

Reading XMLString into Typed Dataset

P: 6
Hi

My program needs to insert records into a strongly typed dataset. The records are passed as a String.

So far I have:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub InsertIntoCustomersTable(ByVal XMLString As String)
  2.  
  3.          Dim sr As New System.IO.StringReader(XMLString) 
  4.  
  5.         '  Read in the XMLString to populate the table
  6.         Mssqlds.Customer.ReadXml(sr)
  7.  
  8.         '  Update db
  9.         Me.CustomerTableAdapter.Update(Mssqlds.Customer)
  10.  
  11.     End Sub
This doesnt error but no rows are added to my Customer datatable. The columns are added but no data.

If I use an untyped dataset:

Expand|Select|Wrap|Line Numbers
  1.     Private Sub InsertIntoCustomersTable(ByVal XMLString As String)
  2.  
  3.         Dim ds As New DataSet              
  4.         Dim da As New MySqlDataAdapter
  5.         Dim sr As New System.IO.StringReader(XMLString)
  6.  
  7.         ' Set the data adapter statements
  8.         getCustomerDataset(ds, da)
  9.  
  10.         ds.ReadXml(sr, XmlReadMode.IgnoreSchema)
  11.  
  12.     End Sub
This loads the records into new rows of the Customer datatable.

How do I load XML stored as a string into a typed dataset datatable so I can call .update?

Thanks

Darren
Apr 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: 6
My XML that is contained in the XMLString variable looks like:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <Customers>
  3.     <Customer>
  4.         <customer_id>2931</customer_id>
  5.         <email>my_name@domain.co.uk</email>        <password>ab8a754d78af898c0816282a0c34d53c</password>
  6.         <title>Mr</title>
  7.         <firstName>Darren</firstName>
  8.         <lastName>Rhymer</lastName>
  9.         <add_1>35 High Street</add_1>
  10.         <add_2/>
  11.         <town>Trowbridge</town>
  12.         <county>Wiltshire</county>
  13.         <zoneId>367</zoneId>
  14.         <postcode>BA14 5RTpostcode>
  15.         <country>225</country>
  16.         <phone>01234 555666</phone>
  17.         <mobile/>
  18.         <regTime>1175250521</regTime>
  19.         <ipAddress>88.23.23.121</ipAddress>
  20.         <noOrders>1</noOrders>
  21.         <optIn1st>0</optIn1st>
  22.         <htmlEmail>1</htmlEmail>
  23.         <type>1</type>
  24.     </Customer>
  25. </Customers>
Apr 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.