C# &引用;参数化查询需要一个未提供的参数";错误

C# &引用;参数化查询需要一个未提供的参数";错误,c#,sql,dataadapter,C#,Sql,Dataadapter,我正在编写一个代码来实现一个应用程序。错误显示 参数化查询“@original\u controllerIP nvchar(19),@IsNull\u ControllerName int”需要未提供的参数@IsNull\u ControllerName 我已尝试为控制器添加原始\u ControllerIPName和所有其他参数,但没有成功 公共虚拟整数删除(字符串原始\u ControllerIP){ 如果((原始控制器IP==null)){ 抛出新的全局::System.ArgumentN

我正在编写一个代码来实现一个应用程序。错误显示

参数化查询“@original\u controllerIP nvchar(19),@IsNull\u ControllerName int”需要未提供的参数@IsNull\u ControllerName

我已尝试为控制器添加
原始\u ControllerIPName
和所有其他参数,但没有成功

公共虚拟整数删除(字符串原始\u ControllerIP){
如果((原始控制器IP==null)){
抛出新的全局::System.ArgumentNullException(“原始控制器IP”);
}
否则{
this.Adapter.DeleteCommand.Parameters[0].Value=((字符串)(原始控件IP));
}
全局::System.Data.ConnectionState previousConnectionState=this.Adapter.DeleteCommand.Connection.State;
if(((this.Adapter.DeleteCommand.Connection.State&global::System.Data.ConnectionState.Open)
!=全局::System.Data.ConnectionState.Open){
this.Adapter.DeleteCommand.Connection.Open();
}
试一试{
int returnValue=this.Adapter.DeleteCommand.ExecuteNonQuery();
返回值;
}
最后{
if((previousConnectionState==global::System.Data.ConnectionState.Closed)){
this.Adapter.DeleteCommand.Connection.Close();
}
}
}
参数如下所示:

this._adapter.DeleteCommand = new global::System.Data.SqlClient.SqlCommand();
        this._adapter.DeleteCommand.Connection = this.Connection;
        this._adapter.DeleteCommand.CommandText = @"DELETE FROM [ControllersData] WHERE (([ControllerIP] = @Original_ControllerIP) AND ((@IsNull_ControllerName = 1 AND [ControllerName] IS NULL) OR ([ControllerName] = @Original_ControllerName)) AND ((@IsNull_ControllerMac = 1 AND [ControllerMac] IS NULL) OR ([ControllerMac] = @Original_ControllerMac)) AND ((@IsNull_ControllerStatus = 1 AND [ControllerStatus] IS NULL) OR ([ControllerStatus] = @Original_ControllerStatus)))";
        this._adapter.DeleteCommand.CommandType = global::System.Data.CommandType.Text;
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_ControllerIP", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerIP", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IsNull_ControllerName", global::System.Data.SqlDbType.Int, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerName", global::System.Data.DataRowVersion.Original, true, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_ControllerName", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerName", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IsNull_ControllerMac", global::System.Data.SqlDbType.Int, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerMac", global::System.Data.DataRowVersion.Original, true, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_ControllerMac", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerMac", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@IsNull_ControllerStatus", global::System.Data.SqlDbType.Int, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerStatus", global::System.Data.DataRowVersion.Original, true, null, "", "", ""));
        this._adapter.DeleteCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@Original_ControllerStatus", global::System.Data.SqlDbType.NVarChar, 0, global::System.Data.ParameterDirection.Input, 0, 0, "ControllerStatus", global::System.Data.DataRowVersion.Original, false, null, "", "", ""));

您的查询需要两个参数:
original\u controllerIP
IsNull\u ControllerName
,但您只提供了一个:

this.Adapter.DeleteCommand.Parameters[0].Value = ((string)(Original_ControllerIP));
您应该提供两个参数:

this.Adapter.DeleteCommand.Parameters[0].Value = ((string)(Original_ControllerIP));
this.Adapter.DeleteCommand.Parameters[1].Value = VALUE IN HERE;

如果您的查询只接受一个参数,则可能需要刷新/更新数据适配器

能否显示DeleteCommand.Parameters的设置位置?是否您的查询需要两个参数,但您只设置了一个?我这样问是因为我只看到了
delete命令的一个参数的一个assignment
这看起来像是生成的代码(
global::
前缀和多余的括号是指示符)。
@IsNull\u ControllerName
参数可能是后来添加的,需要重新生成此代码。@sr28刚刚添加了Jonathan和madreflection提到的问题中的参数设置,预计有2个参数;原始控制器IP和IsNull控制器名称。两者都需要提供。