473,387 Members | 3,787 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,387 software developers and data experts.

how to deal with null value from database

Hi

Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it
(string, integer, boolean type field)

Thank

willia

Nov 22 '05 #1
8 3957
You should check if it a null. You can use the IsDBNull function in VB. The
DataRow has an IsNull method, and the data reader an IsDBNull method, that
can be used from any language, since they're just methods on those classes.

If it turns out the value is a null - then you must handle that
appropriately. Otherwise, you can cast/convert the value to the appropriate
datatype.

"william" <an*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,

Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it? (string, integer, boolean type field).

Thanks

william

Nov 22 '05 #2
You should check if it a null. You can use the IsDBNull function in VB. The
DataRow has an IsNull method, and the data reader an IsDBNull method, that
can be used from any language, since they're just methods on those classes.

If it turns out the value is a null - then you must handle that
appropriately. Otherwise, you can cast/convert the value to the appropriate
datatype.

"william" <an*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,

Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it? (string, integer, boolean type field).

Thanks

william

Nov 22 '05 #3
william wrote:
Hi,

Whwn I select from database using ADO.NET, if the data is null value
in database, how should I handle it? (string, integer, boolean type
field).


The value is System.DBNull. You can check for it by using static bool
Convert.IsDBNullI(object).

--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.

Nov 22 '05 #4
william wrote:
Hi,

Whwn I select from database using ADO.NET, if the data is null value
in database, how should I handle it? (string, integer, boolean type
field).


The value is System.DBNull. You can check for it by using static bool
Convert.IsDBNullI(object).

--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.

Nov 22 '05 #5
Checking using IsDBNull is a universal solution. But if you are dealing with
only strings, just append an empty string.

Eg., curRow("StrinColumn1") & ""

This will convert the null value to empty string and thus error is avoided.
I am using this technique successfully from VB3 days when only dealing with
string columns. This is simple and executes faster as no function call is
involved.

ThanQ...
"william" <an*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,

Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it? (string, integer, boolean type field).

Thanks

william

Nov 22 '05 #6
Checking using IsDBNull is a universal solution. But if you are dealing with
only strings, just append an empty string.

Eg., curRow("StrinColumn1") & ""

This will convert the null value to empty string and thus error is avoided.
I am using this technique successfully from VB3 days when only dealing with
string columns. This is simple and executes faster as no function call is
involved.

ThanQ...
"william" <an*******@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Hi,

Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it? (string, integer, boolean type field).

Thanks

william

Nov 22 '05 #7
Shanti <es*******@hotmail.com> wrote:
Checking using IsDBNull is a universal solution. But if you are dealing with
only strings, just append an empty string.

Eg., curRow("StrinColumn1") & ""

This will convert the null value to empty string and thus error is avoided.
I am using this technique successfully from VB3 days when only dealing with
string columns. This is simple and executes faster as no function call is
involved.


You don't need a function call if you just check whether the value is
an instance of DBNull either (if (value is DBNull) in C#). The problem
with your way of doing things is that it treats empty strings as nulls
as well, when they're not. You may well want to distinguish between the
two.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #8
Shanti <es*******@hotmail.com> wrote:
Checking using IsDBNull is a universal solution. But if you are dealing with
only strings, just append an empty string.

Eg., curRow("StrinColumn1") & ""

This will convert the null value to empty string and thus error is avoided.
I am using this technique successfully from VB3 days when only dealing with
string columns. This is simple and executes faster as no function call is
involved.


You don't need a function call if you just check whether the value is
an instance of DBNull either (if (value is DBNull) in C#). The problem
with your way of doing things is that it treats empty strings as nulls
as well, when they're not. You may well want to distinguish between the
two.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
8
by: william | last post by:
Hi Whwn I select from database using ADO.NET, if the data is null value in database, how should I handle it (string, integer, boolean type field) Thank willia
5
by: TomislaW | last post by:
I have integers in my database that can be null. I read them with SqlDataReader and show them to Repeater. Since integer can not be null in c#, I set null integer to -1. My project is 3-tier and it...
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...
5
by: Woody Splawn | last post by:
I have some code that looks like this: Dim SSN, LName, FName, M As String mySqlConnection = New SqlConnection(myConnectionString) Dim sql_Command As New SqlCommand( _ "Select SSN, LName, FName,...
1
by: news.wanadoo.nl | last post by:
Hi, I have found whit google this form in this group. But i'n not good in javascript :(. I try and error normal but i only error now :P Whit i now want to now how can i get access to the vars...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.