gilllyo
asked on
DataReader has rows but no Data?
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();
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();
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
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
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.
try using getfloat or getdouble according to your data model
hth,
A.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you...
some times writing sql command in such way raise an error
correction..
'" + name + "' have a space before and after the +'s
cheers