473,385 Members | 1,693 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,385 software developers and data experts.

Null value in Datareader

Hi Group,
How can I overcome the issue of null values in a datareader. I keep getting
the dbnull error when I try to assign a null value to a text box.

TIA

Jun 27 '08 #1
5 12958
On May 29, 3:02*pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I overcome the issue of null values in a datareader. *I keep getting
the dbnull error when I try to assign a null value to a text box.

TIA
Check out the DataReader IsDBNull Method.
Jun 27 '08 #2
You need to test each and every field in your dataset if it is Null before
using it.

This annoyed me so much that I now just make all my database fields
non-nullable.

A common solution is to have a "NoNull" function or something that
automatically changes nulls to zero or empty string.

--
David Streeter
Synchrotech Software
Sydney Australia
"za***@construction-imaging.com" wrote:
On May 29, 3:02 pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I overcome the issue of null values in a datareader. I keep getting
the dbnull error when I try to assign a null value to a text box.

TIA

Check out the DataReader IsDBNull Method.
Jun 27 '08 #3
On May 29, 3:02 pm, "axapta" <jas.jac...@gmail.comwrote:
Hi Group,
How can I overcome the issue of null values in a datareader. I keep getting
the dbnull error when I try to assign a null value to a text box.

TIA
It's actually quite easy, and requires no checks for DbNull if you
going to a string value:

//////////////
If dataReader.Read() Then
textBox1.Text = dr("MyColumnName").ToString()
End If
/////////////

The ToString() method will happily turn a DbNull into a blank string
("") when called. It's a great time saver :-)

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #4
I always had to do a check on my datareader values as they came out of
the database.

if not dr[0] is DBNull.Value then
textbox1.text = dr[0].ToString() 'I always have option strict on
end if

Kind of a pain, which is why I stopped using null unless I had to.

Jun 27 '08 #5
On May 30, 9:53 am, "cfps.Christian" <ge0193...@otc.eduwrote:
I always had to do a check on my datareader values as they came out of
the database.

if not dr[0] is DBNull.Value then
textbox1.text = dr[0].ToString() 'I always have option strict on
end if

Kind of a pain, which is why I stopped using null unless I had to.
You should be able to just do "textbox1.text = dr[0].ToString()" since
as written above the ToString will convert a dbnull to a blank string.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #6

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

Similar topics

7
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's...
5
by: Rene | last post by:
I have my object model thing going with some classes that contain properties that are saved into a database. Some of these properties are *numeric* properties that can be left Null in the database...
1
by: Ravikanth[MVP] | last post by:
Hi Try this: finally ' Always call Close when done reading. if Not (myDataReader is Nothing) myDataReader.Close() end if Ravikanth
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
4
by: Lakota61 | last post by:
I have an application where a database entity that progresses through a cycle. As it completes a step along the cycle, a todays date is assign to one of the date columns in the table row. However...
4
by: Learner | last post by:
Hello, This my a method to call a stored proce and uses a DataReader to read the data in the below method I am trying to assign a null value to my datareader variable Dim datareader As...
2
by: RSH | last post by:
I have a situation where I am looping through a datareader's rows. An exception is being generated when I attempt to check the value of a Boolean field where it has a null value:\ If...
10
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following three files. 1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to populate a simple <asp:ListBoxcontrol. 2. The UserDetails.cs file creates a Namespace...
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...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.