Stored procedure parameter

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
 
L

Larry Lard

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top