0
votes

I am working on a code to implement an application. The error shows

The parameterized query'@original_controllerIP nvchar(19), @IsNull_ControllerName int' expects the parameter @IsNull_ControllerName which was not supplied.

I have tried adding Original_ControllerIPName and all other parameters for the controller but did not work.

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

The parameters are like this:

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, "", "", ""));
1
Can you show where the DeleteCommand.Parameters are being setup? - sr28
Could it be that your query expects 2 parameter but you only set one? I'm asking because I see only one assigment for a parameter of your DeleteCommand - Ackdari
This looks like generated code (the global:: prefix and superfluous parentheses are indicators). The @IsNull_ControllerName parameter was likely added later and this code needs to be regenerated. - madreflection
@sr28 just added the parameters setup in the question - Sudha
As mentioned by Jonathan and madreflection, 2 parameters are expected; Original_ControllerIP and IsNull_ControllerName. Both will need to be supplied. - sr28

1 Answers

1
votes

Your query is expecting 2 parameters: original_controllerIP and IsNull_ControllerName, but you are only supplying one:

this.Adapter.DeleteCommand.Parameters[0].Value = ((string)(Original_ControllerIP));

You should provide both parameters:

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

If your query should only accept one parameter, it's possible you need to refresh / update your data adapter