将数据从访问数据库传输到SQL Server

时间:2013-07-10 14:29:39

标签: .net sql vb.net ms-access-2010

我正在尝试将Access 2010数据中的一些数据字符串传输到Access 2010中的SQL服务器。我不知道如何处理它,或者SQL语句的外观是什么样的它,我是否应该打开数据库或什么。一些指导意见会受到关注。

1 个答案:

答案 0 :(得分:0)

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

数据库连接。打开()

    '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()