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

Re: How to process datareader nulls coming from datareader?

JB wrote:
I am using a datareader to reader a table. The table may have some null
values in it. The thing is that I need to process the row whether the field
has null values in it or not. The "Swim" field in this table will have null
values in it. The problem is that when I try to read the field with a null
value I get the error message stating:

"unable to cast object of type 'System.DBNull' to type 'System.String'.
reader =
selectCommand.ExecuteReader(CommandBehavior.Single Result);
while (reader.Read())
{
WillUsedList WillUsed = new WillUsedList((int)reader["PoolLoc
"],(string)reader["Swims"]);
if(!reader.IsDBNull(swimcol))
{
// use (string)reader[swimcol]
}
else
{
// use some default value maybe null
}
WillUsed. PoolAddr = (int)reader["PoolLoc"];
WillUsed. PollHeat = (string)reader["Swims"];
nuList.Add(WillUsed.PoolAddr);
nuList.Add(WillUsed. PollHeat);
}
reader.Close();
Arne
Nov 1 '08 #1
1 3210
Hello Arne

Actually the error points to the module where the property is set and
not when the column is read from the datareader. But if you say it is a
datareader problem, if I am reading a table with lets say for example 25
columns does that mean write 25 "if" statements (one for each column) or is
it that the datareader is reading the null column and when it hits the
propery set module there is some way to deal with it there?
--
JB
"Arne Vajhøj" wrote:
JB wrote:
I am using a datareader to reader a table. The table may have some null
values in it. The thing is that I need to process the row whether the field
has null values in it or not. The "Swim" field in this table will have null
values in it. The problem is that when I try to read the field with a null
value I get the error message stating:

"unable to cast object of type 'System.DBNull' to type 'System.String'.
reader =
selectCommand.ExecuteReader(CommandBehavior.Single Result);
while (reader.Read())
{
WillUsedList WillUsed = new WillUsedList((int)reader["PoolLoc
"],(string)reader["Swims"]);

if(!reader.IsDBNull(swimcol))
{
// use (string)reader[swimcol]
}
else
{
// use some default value maybe null
}
WillUsed. PoolAddr = (int)reader["PoolLoc"];
WillUsed. PollHeat = (string)reader["Swims"];
nuList.Add(WillUsed.PoolAddr);
nuList.Add(WillUsed. PollHeat);
}
reader.Close();

Arne
Nov 3 '08 #2

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

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
7
by: DS | last post by:
Is there a way to automatically close the data reader connection? I'm using the MS Data Access Application block to substantially {entirely} separate the data access layer (DAL) from the business...
14
by: tshad | last post by:
I have people telling me that I should set up objects for my tables, but I am finding the Null problem makes that difficult. It isn't a big problem if you are not updating the table, but if you...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
1
by: Adrian Turner | last post by:
I am just starting developing with .Net(Have used asp for years). I have created a very simple upload page which once uploaded opens the file(excel) and displays the data. If I Attempt to re-run...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
3
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hello, I've eliminated the bulk of code, this should be sufficient: byte fromEncrypt; string sDecryptedString; //Read the data out of the crypto stream. csDecrypt.Read(fromEncrypt, 0,...
5
by: axapta | last post by:
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
2
by: pvong | last post by:
Doing this in VB.NET w VS2008. In my Sql, I have a SmallDateTime datatype. I have a simple TextBox1. I have a simple DataReader set up to pull this value. All I want is the time piece and...
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
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: 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
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...

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.