none
Parameter issue RRS feed

  • Question

  • I have an insert method that gets passed variables and it performs the inserts in batch mode in a for loop. 

     

    In my SQL Server table I have some fields that allows nulls however in a dynamic query if I don't supply a parameter value I get an exception "expects parameter @whatever, which was not supplied

     

    Thursday, June 26, 2008 10:27 PM

Answers

  • I fixed it:

    //d is a parameter being passed in.

     

    SqlParameter cntrefno = new SqlParameter("@CNTREFNO", SqlDbType.VarChar, 20);

    cntrefno.IsNullable = true;

    if (d == null)

        cntrefno.Value = DBNull.Value;

    else

       cntrefno.Value = d;

    cmd.Parameters.Add(cntrefno);

    Thursday, June 26, 2008 10:46 PM