473,320 Members | 1,949 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,320 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 3951
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.