0

I have a problem with supply parameter to stored procedure with odbc, this is my procedure:

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

When I run this procedure, I get an error message:

ERROR [42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Procedure or function 'addMasterBarangKeluar' expects parameter '@kodeUser', which was not supplied.

I think I have supplied all the parameters.

Can anybody help me please?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
GangOne Style
  • 81
  • 2
  • 4
  • 14

2 Answers2

3

Try like that :

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

Show : Execute Parameterized SQL StoredProcedure via ODBC

Community
  • 1
  • 1
  • voila.. thanks @WISNIEWSKI, i type this code on "command.commandText = "{call addMasterBarangKeluar (?,?,?,?,?,?,?,?)}"" – GangOne Style Oct 09 '13 at 09:27
-1

Here is the answer:

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

The stored procedure name will be written in this way {call addMasterBarangKeluar (?)} for Mysql for calling the procedure from back end In Vb.net And C#

But in Sql Server we write only:

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

Procedure name will be written directly.

This is code is correct and helps me for using an ODBC connection.

Benjamin Lowry
  • 3,730
  • 1
  • 23
  • 27