473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to update a DataSet read from XML file ?

rizwan6feb
108 100+
I am working on an application in VB.NET and MySql. I am getting a duplicate entry for key 1 error. My application goes through the following steps.

1. Populate my DataSet from the database.
2. Make changes in the DataSet
3. Write the DataSet into XML file using the following statement

Expand|Select|Wrap|Line Numbers
  1. ds.WriteXml("file1.xml", XmlWriteMode.WriteSchema)
4. Read the DataSet from the XML file (after restarting the application) using the following code
Expand|Select|Wrap|Line Numbers
  1. ds.ReadXml("file1.xml", XmlReadMode.ReadSchema)

After populating the dataset from XML file, when i update it back in the database, i receive duplicate entry error (even if i have not added any record to the dataset after populating the dataset from xml file)
Sep 19 '08 #1
4 2728
PRR
750 Expert 512MB
As far as i can see you are tryin to put duplicate values to database ...as the dataset n xml already has rows that are present in database... got it ?
I am working on an application in VB.NET and MySql. I am getting a duplicate entry for key 1 error. My application goes through the following steps.

1. Populate my DataSet from the database. lets say you have 10 rows from databse
2. Make changes in the DataSet // You add 2 more rows so 12
3. Write the DataSet into XML file using the following statement // now 12 rows to XML file

Expand|Select|Wrap|Line Numbers
  1. ds.WriteXml("file1.xml", XmlWriteMode.WriteSchema)
4. Read the DataSet from the XML file (after restarting the application) using the following code // 12 rows read
Expand|Select|Wrap|Line Numbers
  1. ds.ReadXml("file1.xml", XmlReadMode.ReadSchema)

After populating the dataset from XML file, when i update it back in the database, i receive duplicate entry error (even if i have not added any record to the dataset after populating the dataset from xml file)
now thats because you are updating 12 rows... 10 are duplicate
Sep 19 '08 #2
rizwan6feb
108 100+
Yes but how can i make sure that only the records which are added, modified or deleted should be updated in the database
Sep 19 '08 #3
rizwan6feb
108 100+
Still looking for solution
Sep 20 '08 #4
PRR
750 Expert 512MB
Still looking for solution
Put the primary keys in a List<String> or any other column that is unique... compare with value in DAtaset .. and if its not there insert into database...
Sep 22 '08 #5

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

Similar topics

2
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
2
by: siaj | last post by:
Hi.. I m just trying to learn using XML file as a datastore. I am reading a dataset from a XML file and then trying to update the XML file with some changes in the dataset. My code is as...
4
by: Alan Silver | last post by:
Hello, I have a site that stores some info in an XML file. The file is pretty simple, of the form... <Site> <SiteName>Fred's Ferrets</SiteName> <SomeVar>Whatever</SomeVar> .... etc ......
2
by: Calvin KD | last post by:
Hi everyone, I know the solution to my problem is probably very simple but I just can't seem to figure out how to do it. My problem is, I have an XML file as a datastore, I read it into a dataset...
0
by: Vijay Balki | last post by:
I am fetching data in DataSet - myDataSet, from a remote database using a Web Service in my VB.NET client..Once I fetch it I store the data in XML file (myXMLFile) using the WriteXML method of the...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
1
by: shyamspandey | last post by:
Hi there! I'm a newbie in this area and have assigned, appears to be, tough task. Please help me out. I have to update 3 different database server(Sybase / MYSQL / MS SQL) using a client...
0
by: tom | last post by:
When I try to read in a csv file it gives me this error message. 'Cannot update. Database or object is read-only.' If I change the extension to txt it processes just fine. I have googled all...
7
AHayes
by: AHayes | last post by:
I've been searching online for a while now with no luck, so I'll try the friendly folk here. _The Problem I have a dataset/dataview that's getting its data from an XML file (which we're using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.