469,592 Members | 2,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Null, DBNull, Nothing, VBNullstring

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
Mar 23 '06 #1
3 11393
Larry wrote:
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

Mar 23 '06 #2
Thank You Chris,
I appreciate your answer.

Larry

I Don't Like Spam wrote:
Larry wrote:
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

Mar 23 '06 #3
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

"Larry" <bl***@Blifff.com> schreef in bericht
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Mar 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by bill | last post: by
3 posts views Thread by martin | last post: by
5 posts views Thread by simon | last post: by
1 post views Thread by lydia sista via DotNetMonster.com | last post: by
4 posts views Thread by Andrew Baker | last post: by
17 posts views Thread by John | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.