0
votes

I'm trying to execute a stored procedure using ODBC which has a parameter, but each time I do I get the following:

ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function 'aaPRO_CloseCall' expects parameter '@FaultID', which was not supplied.

My code is:

Dim I As Integer = Convert.ToInt32(LogIDTextBox.Text)
Dim ConnString As String = "Dsn=Test"
Dim Conn As Odbc.OdbcConnection = New Odbc.OdbcConnection(ConnString)
Dim cmd As New Odbc.OdbcCommand("aaPRO_closecall", Conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@FaultID", I)
Conn.Open()
cmd.ExecuteNonQuery()
Conn.Close()

I'm new to Visual Studio and I can't see what I've got wrong. I'd be very grateful if anyone can help.

1
AFAIK you cannot use @names with ODBC, only question marks. See ODBC connection to MySQL won't add values. - GSerg
How is the stored procedure defined? - Gordon Linoff

1 Answers

0
votes

This is what I did in the end

         'Create the ODBC connection
        Dim Conn As Odbc.OdbcConnection = New Odbc.OdbcConnection(ConnString)
        Conn.Open()

        'Add the call to the stored procedure including the connection
        Dim cmd As New Odbc.OdbcCommand("{ CALL aaPRO_closecall(?) }", Conn)
        cmd.CommandType = CommandType.StoredProcedure

        'add the parameter to the stored procedure
        Dim MyParm As OdbcParameter = cmd.Parameters.Add("@FaultID", OdbcType.Int)
        MyParm.Value = FL

        'Execute the procedure
        cmd.ExecuteNonQuery()

        'clean up after
        Conn.Close()
        Conn.Dispose()

Thanks for your help.