【发布时间】:2017-02-03 10:07:11
【问题描述】:
我知道已经有很多关于此的问题,但是,我没有看到任何似乎可以解决我的问题的问题。
我有这个代码
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();
}
}
和错误。 . .
错误 [42000] [Microsoft][ODBC SQL Server 驱动程序][SQL Server]程序 或函数“spSound_Insert”需要参数“@uid”, 那是不供给的。在 System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) 在 System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior 行为,字符串方法,布尔需要读取器,对象[] 方法参数, SQL_API odbcApiMethod) 在 System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior 行为,字符串方法,布尔需要读取器)在 System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
我尝试过使用 AddWithValue,但它给了我同样的问题。
这里是 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;
我稍微更改了名称,但是当我在 sql 控制台中运行 sp 时,似乎可以按预期工作。
【问题讨论】:
-
听起来像是存储过程中的东西而不是显示的代码。
-
请出示
spSound_Insert的代码。 -
我稍微改了一下名字...我也在 sql 控制台中对其进行了测试,它似乎按预期工作。
标签: c# sql-server odbc