473,406 Members | 2,549 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,406 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 3958
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: 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...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.