Setting to DBNull

S

Scott M.

How do I set a value to DBNull so that it will pass into SQL Server without
throwing an error.

The field type in SQL is "Time" and nulls are allowed in the field. I have
a textbox that may, or may not, have a time value in it. If it does, there
is no problem, but if it doesn't then I must set the SQL field to a null
vaule, but in VB.NET, you use DBNull and can't assign that value by x =
DBNull.

I need to be able to do this because the SQL table may have had a time in it
already and if the user passes an empty string, that means they wish to
remove the time from the SQL table (therefore setting it to <NULL>).

Thanks!
 
K

Kevin Yu [MSFT]

Thanks for William's response.

Hi Scott,

I'm glad to know that you have had the problem resolved. DBNull is a
singleton class whose value is DBNull.Value. "DBNull" is a class name which
cannot be assigned to a variable. So we have to use Parameter.Value =
DBNull.Value instead.

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

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