2010-05-02 53 views
1

移動的資料,因此,這裏有雲:OLEDBCommandBuilder和翻過表

我需要將數據從表中的Access數據庫從另一個Access數據庫複製,另一個表。從表

列名是一樣的,除了一個事實,即從表中有5列,該表有6

這裏是我的代碼:

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") 

因爲FROM表中有5行,另一個有6,我試圖使用由第一個表的DataAdapter生成的InsertCommand。

它的工作原理,只是它將FROMTABLE中的數據插入到同一個FROMTABLE中,而不是TOTABLE。

回答

0

我想你應該在的行執行查詢:

conn_string2 = ";Database=c:\Docs\DBFrom.mdb;" 
    query1 = "INSERT INTO nomenclator_produse (field1) " _ 
    & "SELECT f.Field1 from [" & conn_string2 & "].nomenclator_produse f " _ 
    & "LEFT JOIN nomenclator_produse t " _ 
    & "ON f.id=t.id WHERE t.id Is Null"