Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Passing a null value as a SqlParameter()

Author  Topic 

toot
Starting Member

2 Posts

Posted - 2003-05-07 : 11:46:29
Hi,
I'm trying to pass a null value as a SqlParameter() to a stored procedure.

SqlParameter parms = new SqlParameter();
parms = cmd.Parameters.Add(new SqlParameter("@curr_type_desc", SqlDbType.VarChar));
parms.Direction = ParameterDirection.Input;
cmd.Parameters["@curr_type_desc"].Value = this.currTypeDesc;

This fails when currTypeDesc is null :
Procedure 'sp_InsertCurrency' expects arameter '@alt_curr_code_desc', which was not supplied

Can anyone enlighten me with the correct way to do this please?
Thanks,
Chris

chadmat
The Chadinator

1974 Posts

Posted - 2003-05-07 : 12:00:53
Try passing in DBNull.Value when it is null. You might also want to default the parameter to NULL in the stored proc, then if it is NULL in your code, you don't pass it in.

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page
   

- Advertisement -