0

我在使用 odbc 向存储过程提供参数时遇到问题,这是我的过程:

Dim Command As New OdbcCommand
Dim oDataAdapter As New OdbcDataAdapter
Dim dbTrans As OdbcTransaction

Public NoNotax As String

Sub addBarangKeluar(ByVal kodeUser As String, ByVal totalJual As Long, ByVal totalDiskon As Long, ByVal totalJual2 As Long, ByVal bayar As Long, ByVal kembali As Long, ByVal kodeCust As String, ByVal odata As DataTable)
    Dim i As Integer
    Dim Nonota As String
    Dim parameter As OdbcParameter

    modKoneksi.bukaKoneksi()
    DBTrans = modKoneksi.koneksi.BeginTransaction
    command.Connection = modKoneksi.koneksidb
    command.Transaction = DBTrans
    command.CommandType = CommandType.StoredProcedure
    Command.CommandText = "addMasterBarangKeluar "

    Try
        Command.Parameters.Add("@kodeUser", OdbcType.VarChar, 10, ParameterDirection.Input).Value = kodeUser
        Command.Parameters.Add("@totalJual", OdbcType.BigInt, 20, ParameterDirection.Input).Value = totalJual
        Command.Parameters.Add("@totalDiskon", OdbcType.BigInt, 20, ParameterDirection.Input).Value = totalDiskon
        Command.Parameters.Add("@totalJual2", OdbcType.BigInt, 20, ParameterDirection.Input).Value = totalJual2
        Command.Parameters.Add("@bayar", OdbcType.BigInt, 20, ParameterDirection.Input).Value = bayar
        Command.Parameters.Add("@kembali", OdbcType.BigInt, 20, ParameterDirection.Input).Value = kembali
        Command.Parameters.Add("@kodeCustomer", OdbcType.VarChar, 20, ParameterDirection.Input).Value = kodeCust
        Command.Parameters.Add("@NoNOtanya", OdbcType.VarChar, 20)
        Command.Parameters("@NoNOtanya").Direction = ParameterDirection.Output

        Command.ExecuteNonQuery()

        Nonota = Command.Parameters("@NoNOtanya").Value
        Command.Parameters.Clear()

        Command.CommandType = CommandType.Text
        For i = 0 To odata.Rows.Count - 1
            Command.CommandText = "exec addBarangKeluarDetil '" & Guid.NewGuid.ToString & "','" & Nonota & "','" & odata.Rows(i).Item(0) & "','" & odata.Rows(i).Item(1) & "','" & odata.Rows(i).Item(4) & "','" & odata.Rows(i).Item(3) & "','" & odata.Rows(i).Item(5) & "'"
            Command.ExecuteNonQuery()
        Next
        NoNotax = Nonota
        dbTrans.Commit()
    Catch ex As Exception
        dbTrans.Rollback()
        MsgBox("Pesan Error : " + ex.Message, MsgBoxStyle.Critical, "Error !")
        NoNotax = "0"
    End Try
    Command.Parameters.Clear()
    modKoneksi.tutupKoneksi()

End Sub

当我运行此过程时,我收到一条错误消息:

错误 [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server] 过程或函数“addMasterBarangKeluar”需要参数“@kodeUser”,但未提供该参数。

我想我已经提供了所有参数。

有人可以帮我吗?

4

2 回答 2

3

像这样尝试:

OdbcCommand ODBCCommand = new OdbcCommand("{call addMasterBarangKeluar (?)}", ODBCConnection);
ODBCCommand.CommandType = CommandType.StoredProcedure;

Show :通过 ODBC 执行参数化 SQL StoredProcedure

于 2013-10-09T09:11:25.687 回答
-1

这是答案:

OdbcCommand ODBCCommand = new OdbcCommand("{call addMasterBarangKeluar (?)}", ODBCConnection);

存储过程名称将以这种方式写入{call addMasterBarangKeluar (?)} Mysql 用于从后端调用过程 在 Vb.net 和 C#

但是在 Sql Server 中我们只写:

OdbcCommand ODBCCommand = new OdbcCommand("addMasterBarangKeluar", ODBCConnection); 

程序名称将直接写入。

这是正确的代码,可以帮助我使用 ODBC 连接。

于 2017-01-24T09:34:42.820 回答