Problem using OLEDBCOMMANDBUILDER.

Posted by Lullly on Stack Overflow See other posts from Stack Overflow or by Lullly
Published on 2010-05-02T21:02:57Z Indexed on 2010/05/02 21:07 UTC
Read the original article Hit count: 126

Filed under:
|
|
|

So, here it goes:

I need to copy data from table in access database, in another table from another access database.

Column names from tables are the same, except the fact that the FROM table has 5 columns, the TO table has 6.

here is my code:

dsFrom.Clear()
dsTO.Clear()
        daFrom = Nothing
        daTO = Nothing
        conn_string1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="etc.mdb;"
        conn_string2 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="database.mdb;"
        query1 = "Select * from nomenclator_produse"
        query2 = "Select * from nomenclator_produse"
        Conn1 = New OleDbConnection(conn_string1)
        conn2 = New OleDbConnection(conn_string2)
        Conn1.Open()
        conn2.Open()
        daFrom = New OleDbDataAdapter(query1, Conn1)
        daTO = New OleDbDataAdapter(query2, conn2)
        daFrom.AcceptChangesDuringFill = False
        dsFrom.HasChanges()
        daFrom.Fill(dsFrom, "nomenclator_Produse")
        dsFrom.HasChanges()
        Dim cb = New OleDbCommandBuilder(daFrom)
        dsTO = dsFrom.Copy
        daTO.UpdateCommand = cb.GetUpdateCommand
        daTO.InsertCommand = cb.GetInsertCommand
        daTO.Update(dsTO, "nomenclator_produse")

Because the FROM table has 5 rows and the other has 6, i'm trying to use the InsertCommand generated by the DataAdapter of the first table.

It works, only that it inserts the data from the FROMTABLE in the same FROMTABLE, instead of TOTABLE. :|

please help me :(

© Stack Overflow or respective owner

Related posts about vb

Related posts about 2008