The parameterized query … expects the parameter '@units', which was not supplied

后端 未结 5 2023
耶瑟儿~
耶瑟儿~ 2020-12-01 10:02

I\'m getting this exception:

The parameterized query \'(@Name nvarchar(8),@type nvarchar(8),@units nvarchar(4000),@rang\' expects the parameter \'@uni

5条回答
  •  借酒劲吻你
    2020-12-01 10:51

    This is a method to be reused with multiple parameters:

    public void NullorEmptyParameter(QC.SqlCommand command, string at, string value)
    {
        if (String.IsNullOrEmpty(value))
        {
            command.Parameters.AddWithValue(at, DBNull.Value);
        }
        else
            command.Parameters.AddWithValue(at, value);
    }
    

    And then you can reuse it for as many commands and params:

    NullorEmptyParameter(command, "@Idea_ID", Idea_ID);
    NullorEmptyParameter(command, "@Opportunities_or_Idea", Opportunities_or_Idea);
    

提交回复
热议问题