Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataReader has rows but no Data?

Posted on 2006-06-22
5
Medium Priority
?
523 Views
Last Modified: 2008-02-01
I'm using an MS access database to store data for a program but when I go and try to receive data from the database via the code snippet below. When it get's to reading the data (in the line with the "*No Data*" label the following exception is thrown "No data exists for the row/column." with a source of "System.Data"

How can that happen when the HasRows'  property checks to see if there is data there or not?

OleDbCommand cmd = new OleDbCommand("SELECT * FROM Country WHERE NationID ='"+name+"';", conn);
                OleDbDataReader data = cmd.ExecuteReader();
               
                if (data.HasRows)
                {
     
                    numAirforce.Value = data.GetDecimal(3); *No data*
                    .....
               }
               data.Close();
               conn.Close();
0
Comment
Question by:gilllyo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:t_itanium
ID: 16966496
is the cmd executing properly??? try to use break points and f11 to trace the code......

some times writing sql command in such way raise an error

correction..

'" + name + "' have a space before and after the +'s

cheers
0
 
LVL 6

Expert Comment

by:MuhammadAdil
ID: 16966523
Hi Dear,

I think there is no need of ; and
          "SELECT * FROM Country WHERE NationID ='"+name+"'"
if (data.HasRows)
                {
                   data.Read();
                    numAirforce.Value = data.GetDecimal(3); *No data* // is this column can convert to decimal
                    .....
               }

Regards

Adil
0
 
LVL 11

Expert Comment

by:Agarici
ID: 16966715
when calling data.getdecimal no conversion is made so the column must be of type decimal

try using getfloat or getdouble according to your data model

hth,
A.
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 375 total points
ID: 16967331
Hi,
try like this
if (data.HasRows)
{
    while (data.Read())
     {
      numAirforce.Value = data.GetDecimal(3);
      }
}
else
{
   //do nothing
}

Convert the data.GetDecimal(3) value to  numAirforce's data type

regards
Pradeep
0
 

Author Comment

by:gilllyo
ID: 16968301
Thank you...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question