Dataset merging and saving to database

Talarin

New member
Joined
Mar 16, 2006
Messages
1
Programming Experience
3-5
Hey all,

I'm fairly new to ADO.NET and VB.NET and am having some difficulties with the following code. Basicly, Test1 is the master table with Test2 having the same data as well as some updated data. I only want to move over the updated data. Dataset merging seemed to be my best option. The code runs without error, but the database isn't being updated. What am I missing?

VB.NET:
Imports System
Imports System.Data
Imports System.Data.SqlClient
 
 

Module basGlobal[INDENT]Sub Main()[INDENT]Dim cnnPDA As New SqlConnection(GetPDAConnectionString())
Dim ds1 As New DataSet(), ds2 As New DataSet()
 
cnnPDA.Open()
 
Dim strSQL As String = "Select * from Test1"
Dim da As New SqlDataAdapter(strSQL, cnnPDA)
 
da.Fill(ds1, "Test1")
 
strSQL = "Select T2.* from Test2 T2 Left Join Test1 T1 on T2.Customer = T1.Customer where "
strSQL += "(T1.Data1 <> T2.Data1 or T1.Data2 <> T2.Data2 or T1.Data3 <> T2.Data3)"
da.SelectCommand.CommandText = strSQL
 
da.Fill(ds2, "Test1")
 
ds1.Merge(ds2)
da.Update(ds1, "Test1")
 
cnnPDA.Close()
 

[/INDENT]End Sub
 

[/INDENT]End Module

Thanks for your help.

Tal
 
Top Bottom