簡體   English   中英

“參數化查詢需要未提供的參數”錯誤

[英]“The parameterized query expects a parameter which was not supplied” error

我正在編寫用於實現應用程序的代碼。 錯誤顯示

參數化查詢'@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_controllerIPIsNull_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;

如果查詢僅接受一個參數,則可能需要刷新/更新數據適配器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM