0

我正在尝试将一些数据字符串从我的 Access 2010 数据传输到我在 Access 2010 中的 SQL 服务器。我不知道如何去做,也不知道 SQL 语句会是什么样子,无论是我应该打开两个数据库或什么。将给予一些指导。

4

1 回答 1

0

我发现我可以打开数据库,然后打开 SQL Server。拉出记录,然后同时关闭它们。

数据库连接.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()
于 2013-07-12T14:19:10.677 回答