locked
SqlParameter RRS feed

  • Question

  •  

    Hi,

     

    I have a fairly straightforward question to ask about using the SqlParameter.

     

    Traditionally I would always do the following:

     

    SqlParameter objParam = new SqlParameter();

     

    objParam.ParameterName = "@zzz";

    objParam.Size=255;

    objParam.Value = "whatever";

    etc.....

     

    objCmd.Parameters.Add(objParam);

     

    To try and condense things I attempted the following:

     

    objCmd.Parameters.Add(new SqlParameter("@zzz", SqlDbType.VarChar, 255, "whatever"));

     

    but it doesn't work. I looked at the constructors for SqlParameter and found lots of options that didn't relate to my Parameter. To get round this I added nulls as folows:

     

    objCmd.Parameters.Add(new SqlParameter("@zzz", SqlDbType.VarChar, 255, null, null, null, null, "whatever"));

     

    but it still didn't work as I got the following message:

     

    "cannot convert from '<null>' to 'bool'.

     

    Is there a way around this?

     

    Thanks,

    Kabir

    Monday, June 4, 2007 12:11 PM

All replies


  • The first example does not match any of the available signatures for the call. In the second example you can't just specify null for all of the parameter values. Take a closer look at the documentation for the SqlParameter class.
    Monday, June 4, 2007 12:56 PM