By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Null, DBNull, Nothing, VBNullstring

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.