c# - “参数化查询需要一个未提供的参数”错误
问题描述
我正在编写实现应用程序的代码。错误显示
参数化查询'@original_controllerIP nvchar(19), @IsNull_ControllerName int' 需要未提供的参数@IsNull_ControllerName。
我尝试Original_ControllerIPName
为控制器添加和所有其他参数,但没有奏效。
public virtual int Delete(string Original_ControllerIP) {
if ((Original_ControllerIP == null)) {
throw new global::System.ArgumentNullException("Original_ControllerIP");
}
else {
this.Adapter.DeleteCommand.Parameters[0].Value = ((string)(Original_ControllerIP));
}
global::System.Data.ConnectionState previousConnectionState = this.Adapter.DeleteCommand.Connection.State;
if (((this.Adapter.DeleteCommand.Connection.State & global::System.Data.ConnectionState.Open)
!= global::System.Data.ConnectionState.Open)) {
this.Adapter.DeleteCommand.Connection.Open();
}
try {
int returnValue = this.Adapter.DeleteCommand.ExecuteNonQuery();
return returnValue;
}
finally {
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, "", "", ""));
解决方案
您的查询需要 2 个参数:original_controllerIP
and IsNull_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;
如果您的查询应该只接受一个参数,那么您可能需要刷新/更新您的数据适配器
推荐阅读
- google-cloud-firestore - Firebase Firestore 服务器端规则 - 问题
- python - 如何编写一个通过公共值连接列表的循环?(Python)
- arrays - 如何使用 C 中的寄存器存储类创建数组?
- python - 如何通过修改特定值从另一个字典创建新字典(将两个键的值合二为一)
- p2p - 如何在外部程序中调用 github.com/ethereum/go-ethereum/p2p?
- php - 上传字节的php水印问题
- java - 尝试从 Google 警报中心 API 访问报告时收到 401 未经授权的错误
- assembly - Assembler x64中的push和push word有什么区别?
- laravel - Laravel8 webpack vue extractstyle 输出选择器有点奇怪
- java - 单击时更改按钮颜色 Android Studio