473,378 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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 11649
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: bill | last post by:
How can I insert a record with a null value in one of the fields? I need to use the update method from a data adapter. The data is in a XML file.
3
by: martin | last post by:
Hi, I am using vb.net and I would like to define one of my function parameters to have a default value of null (in this case an sqltranaction object) however I am having a great deal of...
2
by: Stuart | last post by:
Hi there I have a stored procedure on my SQL database that retrieves a wide range of values from about 5 different tables. My end point is to calculate the cost against each line of retrieved...
5
by: simon | last post by:
I use session: If IsDBNull(Session("Source")) Then ' this is the line cause an error bindRptSell() End If But I get an error message: Object variable or With block variable not set....
1
by: lydia sista via DotNetMonster.com | last post by:
HI all how dya check if session is null or does not exist? I tried using if Session("cart")= null then ... end if this doesn't work it says 'null' is not declared. 'null' constant is no...
15
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
4
by: Andrew Baker | last post by:
I have the following code that calles a stored proc in SQLServer. When the output parameter @custref is null (System.DBNull) I cant seem to find a test for this and I get an exception. I know I...
0
by: Benny Raymond | last post by:
reply to: benny@pocketrocks.com if possible: I'm trying to set up a hierarchy system in this database where each row can be related to a previous row. The problem is that when I go to...
17
by: John | last post by:
Hi I have a datadapter with the following SQL; SELECT ID, Company, Status, CompanyType FROM Companies WHERE (@Status IS NULL or @Status = Status) When I try to fill like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.