Stored procedure parameter

  • Thread starter Thread starter Peter Kirk
  • Start date Start date
P

Peter Kirk

Hi

should I be able to set the value for a parameter to a stored procedure to
null? For example:

IDataParameter param = command.CreateParameter();
param.ParameterName = "@id";
param.Value = null;
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int32;
command.Parameters.Add(param);


I keep getting an sql-exception stating that the parameter @id was expected.

Thanks
Peter
 
Peter said:
Hi

should I be able to set the value for a parameter to a stored procedure to
null? For example:

IDataParameter param = command.CreateParameter();
param.ParameterName = "@id";
param.Value = null;
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int32;
command.Parameters.Add(param);

C#'s "null" is not the same thing as a SQL "NULL". The former is the
value of an object reference that references no object; the latter is a
special database value. Instead of what you have, say

param.Value = DBNull.Value;

and you should be ok.
 
Back
Top