ORA-01008:并非所有变量都绑定 - VB.NET Web应用程序

时间:2018-03-19 13:51:28

标签: vb.net oracle

我正在编写一个VB.NET函数来更新一个包含四列的表,如下所示。每次都失败,除了 ORA-01008:并非所有变量都绑定

有人可以帮忙吗?

Public Sub UpdateLog(ByVal intUserID As Integer, ByVal strDesc As String, ByVal intLogID As Integer)

Dim oraConn As OracleConnection

    Dim cmd As OracleCommand

    Try
        cmd = New OracleCommand
        cmd.Parameters.Clear()
        cmd.CommandText = "Insert Into Tbl_Trans_Log(UserID,TransID,TransDate,ActionDone) values (:userId,:logId,:transdate,:action)"
        cmd.CommandType = CommandType.Text
        cmd.BindByName = True

        cmd.Parameters.Add("userId", OracleDbType.Int64).Value = intUserID
        cmd.Parameters.Add("logId", OracleDbType.Int64).Value = intLogID
        cmd.Parameters.Add("transdate", OracleDbType.Date).Value = DateTime.Now
        cmd.Parameters.Add("action", OracleDbType.Varchar2).Value = strDesc

        oraConn = New OracleConnection(ConfigurationManager.ConnectionStrings("connString").ConnectionString)
        oraConn.Open()

        cmd.Connection = oraConn
        cmd.ExecuteNonQuery()



    Catch ex As Exception
        sWriteErrorLog("C:\", "log - sUpdateTransLog -> " & ex.Message)
    Finally
        oraConn.close()
    End Try

End Sub

1 个答案:

答案 0 :(得分:0)

以下代码对我有用。

cmd =新的OracleCommand

        cmd.Parameters.Clear()
        cmd.CommandText = "Insert Into Tbl_Trans_Log(UserID,TransID,TransDate,ActionDone) values (:userId,:logId,:transdate,:action)"
        cmd.CommandType = CommandType.Text
        cmd.BindByName = True

        cmd.Parameters.Add(New OracleParameter(":userId", OracleDbType.Int64)).Value = intUserID
        cmd.Parameters.Add(New OracleParameter(":logId", OracleDbType.Int64)).Value = intLogID
        cmd.Parameters.Add(New OracleParameter(":transdate", OracleDbType.Date)).Value = DateTime.Now
        cmd.Parameters.Add(New OracleParameter(":action", OracleDbType.Varchar2)).Value = strDesc

        oraConn = New OracleConnection(ConfigurationManager.ConnectionStrings("xxxxxxxxx").ConnectionString)
        oraConn.Open()

        cmd.Connection = oraConn
        cmd.ExecuteNonQuery()