Home All Groups Group Topic Archive Search About

Null, DBNull, Nothing, VBNullstring

Author
23 Mar 2006 1:21 AM
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

Author
23 Mar 2006 1:53 AM
I Don't Like Spam
Larry wrote:
Show quoteHide quote
> 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
Author
23 Mar 2006 2:53 AM
Larry
Thank You Chris,
I appreciate your answer.

Larry

I Don't Like Spam wrote:
Show quoteHide quote
> 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
>
Author
23 Mar 2006 8:04 AM
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

Show quoteHide quote
"Larry" <bl***@Blifff.com> schreef in bericht
news:%23m830ehTGHA.5108@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