2013-07-10 220 views
0

我試圖從Access 2010數據中將一些數據字符串傳輸到我在Access 2010中的SQL服務器。我不知道如何去解決這個問題,或者SQL語句看起來是什麼樣的,我是否應該有兩個數據庫打開或什麼。一些指導將受到歡迎。將數據從訪問數據庫傳輸到SQL服務器

+0

的SQL Server這是內部的Access 2010? –

+0

是的,它是某種鏈接。 –

+0

有多少條記錄在談論?該表是否存在於SQL Server中? – maSTAShuFu

回答

0

我發現我可以打開數據庫,然後打開SQL Server。拉記錄然後關閉他們在同一時間。

DatabaseConnection.Open()

'SQL statement for find the records that need to be transfered. 
    Dim SQLCommand2 As New OleDbCommand("SELECT * FROM b_forte WHERE BaleLine = '" & stBaleLine & "' and ProdDate > #" & GlobalVariables.dtLastBaleDateTime & "#", DatabaseConnection) 
    Dim TransferRecord As OleDbDataReader = SQLCommand2.ExecuteReader() 
    If ApplicationPropertiesWindow.DisplayCodechkbx.Checked = True Then 
     MainTextBox.AppendText(Environment.NewLine & "SELECT * FROM b_forte WHERE BaleLine = '" & stBaleLine & "' and ProdDate > #" & GlobalVariables.dtLastBaleDateTime & "#") 
     GlobalVariables.DisplayCode = True 
    End If 
    Do While TransferRecord.Read() 
     ProdDate = TransferRecord.Item("ProdDate") 
     BaleLine = TransferRecord.Item("BaleLine") 
     If BaleLine = "A" Then 
      BaleLineNum = "1" 
     Else 
      BaleLineNum = "2" 
     End If 
     BaleNumber = TransferRecord.Item("BaleNumber") 
     GrossWeight = TransferRecord.Item("GrossWeight") 
     AirDry = TransferRecord.Item("AirDry") 
     InvoiceWeight = TransferRecord.Item("InvoiceWeight") 
     'Start of writing to the SQL server. 
     SQLServerConnection.Open() 
     Dim SQLCommand1 As New SqlCommand("INSERT INTO dbo.b_Pulp_PI_Forte (mill, keyprinter_datetime, bale_line_num, pulp_line_id, bale_id, drop_datetime, bale_gross_weight, bale_airdry_pct, grader_test_flag, status_id, created_by, CreatedDateTime, Who_did_it, Last_change_datetime) VALUES ('850', '" & ProdDate & "', '" & BaleLineNum & "', '" & BaleLine & "', '" & BaleNumber & "', '" & ProdDate & "', '" & GrossWeight & "', '" & AirDry & "', 'N', 'U', 'BaleTrac', '" & Date.Now & "', 'BaleTrac', '" & Date.Now & "')") 
     If ApplicationPropertiesWindow.DisplayCodechkbx.Checked = True Then 
      MainTextBox.AppendText(Environment.NewLine & "INSERT INTO dbo.b_Pulp_PI_Forte (mill, keyprinter_datetime, bale_line_num, pulp_line_id, bale_id, drop_datetime, bale_gross_weight, bale_airdry_pct, grader_test_flag, status_id, created_by, CreatedDateTime, Who_did_it, Last_change_datetime) VALUES ('850', '" & ProdDate & "', '" & BaleLineNum & "', '" & BaleLine & "', '" & BaleNumber & "', '" & ProdDate & "', '" & GrossWeight & "', '" & AirDry & "', 'N', 'U', 'BaleTrac', '" & Date.Now & "', 'BaleTrac', '" & Date.Now & "')") 
      GlobalVariables.DisplayCode = True 
     End If 
     SQLCommand1.Connection = SQLServerConnection 
     SQLCommand1.ExecuteNonQuery() 
     SQLServerConnection.Close() 
相關問題