0

i know there are a lot of questions regarding this already, however, i don't see any that appears to solve my problem.

i have this code

using (var conn = new OdbcConnection(sConn))
{
    const string cmdIns = "spSound_Insert";
    using (var sqlCmdIns = new OdbcCommand(cmdIns, conn))
    {
        sqlCmdIns.CommandType = CommandType.StoredProcedure;
        sqlCmdIns.Parameters.Add("@uid", OdbcType.NVarChar, 40).Value = "123";
        sqlCmdIns.Parameters.Add("@data", OdbcType.VarBinary, -1).Value = new Byte[128];
        sqlCmdIns.Parameters.Add("@enabled", OdbcType.Bit).Value = true;
        sqlCmdIns.Parameters.Add("@note", OdbcType.NVarChar, 128).Value = "test note";

        conn.Open();
        sqlCmdIns.ExecuteNonQuery();
    }
}

and the error . . .

ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure or function 'spSound_Insert' expects parameter '@uid', which was not supplied. at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod) at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader) at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()

i've tried using AddWithValue and it gives me the same problem.

here is the SQL

use [SoundsDB];
go

create procedure [dbo].spSound_Insert
    @uid nvarchar(40),
    @data varbinary(max),
    @enabled bit = 1,
    @note nvarchar(128)
as
begin
    delete from [dbo].[Sound] where [uid] = @uid;

    insert [dbo].[Sound] ([uid], [data], [enabled], [note], [updated])
    values (@uid, @data, @enabled, @note, GETDATE());

end;

i'm changing the names a little, but when i ran the sp in sql console appears to work as expected.

3
  • Sounds like something in the stored procedure not the code shown. Commented Feb 3, 2017 at 1:04
  • 2
    Please show the code of spSound_Insert. Commented Feb 3, 2017 at 1:04
  • i changed the names a little... i also tested it in the sql console, it appeared to work as expected. Commented Feb 3, 2017 at 1:12

1 Answer 1

0

so i searched for parameterName and i found this article https://msdn.microsoft.com/en-us/library/system.data.odbc.odbcparameter.parametername(v=vs.110).aspx

they had a different way of calling a stored proc and it appears to work...

using (var conn = new OdbcConnection(sConn))
{
    const string cmdIns = "{ call spSound_Insert(?,?,?,?) }";
    using (var sqlCmdIns = new OdbcCommand(cmdIns, conn))
    {
        sqlCmdIns.CommandType = CommandType.StoredProcedure;
        sqlCmdIns.Parameters.Add("", OdbcType.NVarChar, 40).Value = "123";
        sqlCmdIns.Parameters.Add("", OdbcType.VarBinary, -1).Value = new Byte[128];
        sqlCmdIns.Parameters.Add("", OdbcType.Bit).Value = true;
        sqlCmdIns.Parameters.Add("", OdbcType.NVarChar, 128).Value = "test note";

        conn.Open();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.