Read from xml file into the database

johmolan

Well-known member
Joined
Oct 11, 2008
Messages
129
Programming Experience
Beginner
I need help with a little problem.

I try to read data from a xml-file and save the data in my database.

I try to use this code:

VB.NET:
Public Sub Filleser1()

        Database4DataSet1.Clear()
        Database4DataSet1.ReadXml("c:\Test1.xml")
        Database4DataSet1.GetChanges()
        Database4DataSet1.AcceptChanges()

        Try
            'Validate()
            'KundeEndr.SammendragBindingSource.EndEdit()
            KundeEndr.SammendragTableAdapter.Update(Database4DataSet1.Sammendrag)
            MsgBox("Update successful")

        Catch ex As Exception
            MsgBox("Update failed")
        End Try
    End Sub

I get the message update successful, but the database is still not updated?

Can someone please help me?
 
Oops I meant AcceptChanges. :( It's been a long day.

You may also need to set your TableAdapter's AcceptChangesDuringFill to False.
 
Now my code look like this:

Public Sub Filleser1()

Database4DataSet1.Clear()
Database4DataSet1.ReadXml("c:\Larsen1.xml")
Database4DataSet1.GetChanges()

Try
Validate()

KundeEndr.SammendragBindingSource.EndEdit()
KundeEndr.SammendragTableAdapter.Update(Database4DataSet1.Sammendrag)
MsgBox("Update successful")

Catch ex As Exception
MsgBox("Update failed")
End Try



End Sub


But my database is still not updated, but my msgbox says it is..
Why is it not working?
 
I just found out that it adds a ned ID to the database instead of replacing the ID that is lpresent. I want to replace the ID, not add a new ID.

Anybody know what I am doing wrong?
 
anybody know how I can either replace the existing data in the database og delete the data and then update it again with the new data?
 
Last edited:
Back
Top