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.
spSound_Insert.