Stored Procedure Syntax

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

Hi, I am attempting to updata a SQL Server record using the stored
procedure's UpdateCommand. Everything works fine if all fields are full,
but if a user clears out a textBox that originally contained a number in it,
then the update bombs out. The field in the table is setup to accept nulls.
What is the proper syntax to store it back?

da.UpdateCommand.Parameter[1].value = ???? <a null> ?????

Any help is greatly appreciated.
 
Greg

da.UpdateCommand.Parameter[1].value = DBNull.Value

Tu-Thac
www.ongtech.co

----- Greg Smith wrote: ----

Hi, I am attempting to updata a SQL Server record using the store
procedure's UpdateCommand. Everything works fine if all fields are full
but if a user clears out a textBox that originally contained a number in it
then the update bombs out. The field in the table is setup to accept nulls
What is the proper syntax to store it back

da.UpdateCommand.Parameter[1].value = ???? <a null> ????

Any help is greatly appreciated
 
Thanks for Tu-Thach's quick response!

Hi

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to assign null value to a
parameter. If there is any misunderstanding, please feel free to let me
know.

Just as Tu-Thach said, we can use DBNull to assign null value to a
parameter. DBNull is a singleton class, which means only one instance of
this class can exist. That sole instance is DBNull.Value.

For more information about DBNull class, please check the following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdbnullclasstopic.asp

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top