Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ODBC命令参数未绑定_C#_Sql Server_Odbc - Fatal编程技术网

C# ODBC命令参数未绑定

C# ODBC命令参数未绑定,c#,sql-server,odbc,C#,Sql Server,Odbc,我知道关于这一点已经有很多问题了,但是,我看不到任何解决我问题的方法 我有这个密码 using (var conn = new OdbcConnection(sConn)) { const string cmdIns = "spSound_Insert"; using (var sqlCmdIns = new OdbcCommand(cmdIns, conn)) { sqlCmdIns.CommandType = CommandType.StoredPro

我知道关于这一点已经有很多问题了,但是,我看不到任何解决我问题的方法

我有这个密码

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 行为、字符串方法、布尔needReader、对象[]方法参数、, 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 console中运行sp时,它似乎按预期工作。

因此我搜索了parameterName,找到了本文

他们有一种不同的调用存储过程的方式,它似乎可以工作

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();
    }
}

听起来像是存储过程中的某些内容,而不是显示的代码。请显示
spSound\u Insert
的代码。我稍微更改了名称。。。我还在sql控制台中对其进行了测试,它似乎按照预期工作。