I am able to check duplicate entry but using "WHERE name = textbox.text " clause within a windows form. Now, in this case the checking of duplicate entries is from one database to another. I want to check if all of those records from first database/table to be inserted are already exist in second database/table.
Below is the code for inserting records. Any idea for modification of my codes is highly appreciated.
Below is the code for inserting records. Any idea for modification of my codes is highly appreciated.
Code:
Dim con1 As New OleDb.OleDbConnection("connection string here")
Dim con2 As New OleDb.OleDbConnection("connection string here")
'Create the data adapter with a SelectCommand using the first connection.
Dim da As New OleDb.OleDbDataAdapter("SELECT Fullname FROM sampletable1 ", con1)
da.InsertCommand = New OleDb.OleDbCommand("INSERT INTO sampletable2 (Fullname) VALUES (@Fullname)", con2)
da.InsertCommand.Parameters.Add("@Fullname", OleDb.OleDbType.VarChar, 50, "Fullname")
'Keep the records in a state where they can be inserted into the destination table.
da.AcceptChangesDuringFill = False
Dim dt As New DataTable
'Get the data from the source database.
da.Fill(dt)
'Save the data to the destination database.
da.Update(dt)
MsgBox("Data Added!")
con1.Dispose()
con2.Dispose()