The SqlParameterCollection only accepts non-null

Asked By Jim Tanner
13-Nov-04 12:08 AM
Earn up to 0 extra points for answering this tough question.
Hi, I'm the guy having problems adding parameters to my SP. I tried out: command.Parameters.Add(new SqlParameter("@role", SqlDbType.Int).Value= 0); and get error: The SqlParameterCollection only accepts non-null SqlParameter type objects, not String objects. Tried to google it and couldn't find anything. This one doesn't make sense.

  Doesn't make sense to me either

Asked By Peter Bromberg
13-Nov-04 08:14 AM
SqlDbType is an enumeration, and ".Int" is one of them. I would try breaking this up - creat the parameter, type and direction , then assign the .Value=0 later. Only other thing I can think of is you may be calling the wrong execute method of your Command object - ExecuteNonQuery instead of ExecuteScalar, for instance. Stuff like this has been known to generate unusual exception messages.

  PS - I have gotten this error

Asked By Peter Bromberg
13-Nov-04 12:57 PM
this is an approach that takes care of it: SqlParameter parm1 = new SqlParameter("@Beginning_Date",SqlDbType.DateTime ); parm1.Value = myDateTimeVariable; command.Parameters.add(parm1);
Create New Account