How to pass a null value for a stored procedure?

G

Guest

Hi friends,

There is a parameter (integer) for a stored procedure. I need to pass a
value in my C# code, like the follows,

System.Data.SqlClient.SqlParameter sp = new
System.Data.SqlClient.SqlParameter("baseID", System.Data.SqlDbType.Int);
sp.Size = 4;
sp.Value = null;

However, I got an error, saying: Procedure 'sp_InsertBase' expects parameter
'@baseID', which was not supplied.

If I assigne a value like this:

sp.Value = 0;

Then it works fine.

I believe something wrong with the null value. Any ideas? I do need to pass
a null value sometimes.

Thanks a lot
 
J

Jeff Dillon

dbNull?

And "why" would you ever call a sproc, with an explicit NULL parameter?
Keep in mind, you can set the default param for a sproc to be null if you
explicitly don't supply a value.

Jeff
 

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