DataAdapter not working after Merge with other Dataset

K

kirck

I have a .sln with one project and one form, i have a table of Access and a
Table of SQLServer

i need update data from access to SQLServer but
Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb") not working



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.OleDbDataAdapter1.Fill(Me.DsMdb1)

Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.OleDbConnection1.Open()

Me.OleDbDataAdapter1.Update(Me.DsMdb1)

Me.OleDbConnection1.Close()

Me.DsSQL1.Merge(Me.DsMdb1)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Me.DsSQL1.AcceptChanges()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Me.SqlConnection1.Open()

Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb")

Me.SqlConnection1.Close()

'Me.DsSQL1.WriteXml("c:\merge.xml")

'Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub
 
G

Guest

I assume you're executing the code by clicking first on Button1, then
Button2, etc.? If so, then you're doing the Me.DsSQL1.AcceptChanges() before
you do the Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb"), so it thinks you
have nothing to update. You don't need to do an .AcceptChanges() because the
..Update() method does that after it updates the database.

Also, you'll want to merge your DataSets before you do the
Me.OleDbDataAdapter1.Update(Me.DsMdb1), not after, for the same reason
(because the .Update() does an .AcceptChanges()) and your merged data will
probably be marked as "Unmodified" and thus not be updated with your Sql
..Update() either.

~~Bonnie
 
C

Cor Ligthert

Kirck,

In addition to Bonnie,

What the acceptchanges does is setting the dataset/datatable in a start
position with all changes accepted as done.

Cor
 
G

Guest

But did you read the rest of my post? The .Update() automatically does an
..AcceptChanges(). You need to rearrange where you do your .Merge().

~~Bonnie



kirck said:
any combination not working
and i execute button1 and button3

"Bonnie Berent [C# MVP]" <[email protected]>
escribió en el mensaje
I assume you're executing the code by clicking first on Button1, then
Button2, etc.? If so, then you're doing the Me.DsSQL1.AcceptChanges()
before
you do the Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb"), so it thinks
you
have nothing to update. You don't need to do an .AcceptChanges() because
the
.Update() method does that after it updates the database.

Also, you'll want to merge your DataSets before you do the
Me.OleDbDataAdapter1.Update(Me.DsMdb1), not after, for the same reason
(because the .Update() does an .AcceptChanges()) and your merged data will
probably be marked as "Unmodified" and thus not be updated with your Sql
.Update() either.

~~Bonnie
 
K

kirck

yes i do
sugest me a solution
thanks




p.d.: I speak spanish, my english isn't very well

"Bonnie Berent [C# MVP]" <[email protected]>
escribió en el mensaje
But did you read the rest of my post? The .Update() automatically does an
.AcceptChanges(). You need to rearrange where you do your .Merge().

~~Bonnie



kirck said:
any combination not working
and i execute button1 and button3

"Bonnie Berent [C# MVP]" <[email protected]>
escribió en el mensaje
I assume you're executing the code by clicking first on Button1, then
Button2, etc.? If so, then you're doing the Me.DsSQL1.AcceptChanges()
before
you do the Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb"), so it
thinks
you
have nothing to update. You don't need to do an .AcceptChanges()
because
the
.Update() method does that after it updates the database.

Also, you'll want to merge your DataSets before you do the
Me.OleDbDataAdapter1.Update(Me.DsMdb1), not after, for the same reason
(because the .Update() does an .AcceptChanges()) and your merged data
will
probably be marked as "Unmodified" and thus not be updated with your
Sql
.Update() either.

~~Bonnie




:

I have a .sln with one project and one form, i have a table of Access
and
a
Table of SQLServer

i need update data from access to SQLServer but
Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb") not working



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.OleDbDataAdapter1.Fill(Me.DsMdb1)

Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

'Me.OleDbConnection1.Open() 'without this sentence

'Me.OleDbDataAdapter1.Update(Me.DsMdb1) 'without this sentence

' Me.OleDbConnection1.Close() 'without this sentence

Me.DsSQL1.Merge(Me.DsMdb1)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

Me.DsSQL1.AcceptChanges()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Me.SqlConnection1.Open()

Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb")

Me.SqlConnection1.Close()

'Me.DsSQL1.WriteXml("c:\merge.xml")

'Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub
 
G

Guest

Well, I said that all you had to do was switch the order of when you do the
..Merge, so basically, just do this (and you don't need the Button2_Click):

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Me.OleDbDataAdapter1.Fill(Me.DsMdb1)

Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.DsSQL1.Merge(Me.DsMdb1)

Me.OleDbConnection1.Open()

Me.OleDbDataAdapter1.Update(Me.DsMdb1)

Me.OleDbConnection1.Close()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click

Me.SqlConnection1.Open()

Me.SqlDataAdapter1.Update(Me.DsSQL1, "CtrlEmb")

Me.SqlConnection1.Close()

'Me.DsSQL1.WriteXml("c:\merge.xml")

'Me.SqlDataAdapter1.Fill(Me.DsSQL1, "CtrlEmb")

End Sub

That should work ... if it doesn't, let me know.

~~Bonnie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top