Null, DBNull, Nothing, VBNullstring

L

Larry

Hi all,

I am coming over from VB 6, learning VB.NET.

I have read and have in front of me, the language reference from
the msdn, on; Behavior of Null has changed, Isdbnull function and
isnothing function.

However, I am still at a loss to know excatly what to do.

When I check a control for a value, (before I send it to a field on a record
in the database), and the user has not entered anything into that
control, What do I check for?
IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four?

What do I put in a field that is going to the datbase, if the user
didn't enter anything into the control?

system.dbnull.value, or Nothing, or vbnullstring or ""

When I get a field back from the database, what do I check for?
IsDBNull, Isnothing, vbnullstring, Len()=zero?


Thanks in Advance,

Larry
 
G

Guest

Larry said:
Hi all,

I am coming over from VB 6, learning VB.NET.

I have read and have in front of me, the language reference from
the msdn, on; Behavior of Null has changed, Isdbnull function and
isnothing function.

However, I am still at a loss to know excatly what to do.

When I check a control for a value, (before I send it to a field on a
record
in the database), and the user has not entered anything into that
control, What do I check for?
IsDBNULL, Isnothing, or vbnullstring, Len()=0, or all four?

What do I put in a field that is going to the datbase, if the user
didn't enter anything into the control?

system.dbnull.value, or Nothing, or vbnullstring or ""

When I get a field back from the database, what do I check for?
IsDBNull, Isnothing, vbnullstring, Len()=zero?


Thanks in Advance,

Larry


Q. "When I check a control for a value, (before I send it to a field on a
record in the database), and the user has not entered anything into that
control, What do I check for?"

A. This depends on the control. A Textbox returns String.Empty when it
blank.


Q. "What do I put in a field that is going to the datbase, if the user
didn't enter anything into the control?"

A. This depends on how you want to handle your system. You can send
DBNull.Value if you want the value to be null, or you can send a default
value in.

Q. "When I get a field back from the database, what do I check for?
IsDBNull, Isnothing, vbnullstring, Len()=zero?"

A. If the database has a null value in it you have to check the value is
dbnull.value before trying to assign it to a variable.
EX: if Reader.GetString(0) is DBNull.Value then ...

Hope it helps
Chris
 
L

Larry

Thank You Chris,
I appreciate your answer.

Larry
Q. "When I check a control for a value, (before I send it to a field on a
record in the database), and the user has not entered anything into that
control, What do I check for?"

A. This depends on the control. A Textbox returns String.Empty when it
blank.


Q. "What do I put in a field that is going to the datbase, if the user
didn't enter anything into the control?"

A. This depends on how you want to handle your system. You can send
DBNull.Value if you want the value to be null, or you can send a default
value in.

Q. "When I get a field back from the database, what do I check for?
IsDBNull, Isnothing, vbnullstring, Len()=zero?"

A. If the database has a null value in it you have to check the value is
dbnull.value before trying to assign it to a variable.
EX: if Reader.GetString(0) is DBNull.Value then ...

Hope it helps
Chris
 
C

Cor Ligthert [MVP]

Larry,

An placeholder for a not yet used value or object IS Nothing
A DB object that is not filled can be tested with DBValue.null
An empty instanced value can be tested with = Nothing while this works as
well for a not instanced value (not an object) because it will be instanced
direct to the base value.

And then there are it seems thousand of otherways which are in fact other
use of the same.
String.empty, string = "" (prefered by the long time regulars in this
newsgroup), ISDBNull

It is VB.Net not C# do it in your organisation in the way as it fits the
culture of your organisation the best.

Cor
 

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