访问表INSERT无法通过VB工作

时间:2014-12-14 02:31:53

标签: sql vb.net access-vba oledb

我在VB中编写程序并尝试插入数据库(之前我已经完成),但它无法正常工作。假设所有参数值都是正确的,那么什么不会导致引发异常或错误,但是不能插入下面代码的行?

Dim sqlString As String = "INSERT INTO ArDetail (ArType, ArTenantNbr, ArInvNbr, ArSeqNbr, ArTransactAmt, ArAmtDue, ArChkNbr) VALUES (?, ?, ?, ?, ?, ?, ?);"
Dim sqlArgs As String(,) = {{"@ArType", "RI"},
                    {"@ArTenantNbr", lblTenantNumber.Text},
                    {"@ArInvNbr", row.Cells("Inv Nbr").Value.ToString},
                    {"@ArSeqNbr", nextSeqNbr.ToString},
                    {"@ArTransactAmt", row.Cells("Paid Amt").Value.ToString},
                    {"@ArAmtDue", "0"},
                    {"@ArChkNbr", txtCheckNumber.Text}}

我附加了这个,所以你可以看到sqlArgs中的信息。 Error screenshot with object explorer on sqlArgs

编辑:有人要求我添加ChangeTableObj()代码


Public Shared Sub ChangeTableObj(ByVal sqlString As String,
                                 Optional ByVal sqlArgs As String(,) = Nothing)

Dim i As Integer

'Instantiate Access database Connection using Connect string in app.config
Dim dbConnObj As OleDb.OleDbConnection = New OleDb.OleDbConnection()
dbConnObj.ConnectionString = My.Settings.TenManDBConnectionString

'Instantiate an OleDb Command Object using the Connection object
Dim cmdObj As New OleDb.OleDbCommand(sqlString, dbConnObj)
cmdObj.CommandType = CommandType.Text

'Add requested parameters to the sql command if given
If Not sqlArgs Is Nothing Then
    For i = 0 To sqlArgs.GetUpperBound(0)
        cmdObj.Parameters.AddWithValue(sqlArgs(i, 0), sqlArgs(i, 1))
    Next i
End If

'Open connection, update database, and close

cmdObj.Connection.Open()
cmdObj.ExecuteNonQuery()
cmdObj.Connection.Close()

End Sub

0 个答案:

没有答案