...

View Full Version : Database access related issue



abhiamity86
06-17-2011, 09:15 AM
Dear Sir,
I have accessed one field from database with datareader.Now I want to check it and the accordinngly want to increase or decrease it.
(e.g. If we got 4 from database and this 4 has been stored in the datareader object(e.g.dr[0] contains 4) now i want to check it aginst 5 if it is 5 then display 6).
I tried below mentioned code for the same -
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
if (dr.GetInt32(0) == 5)
{
Response.Write("6");
}
}
}

But it is giving Exception in if condition is that Specified cast is not valid.
How it is possible.
Pls help me out.

Thanks
Abhishek .

kelvincostner
07-11-2011, 12:00 PM
Try this,

SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
if (dr(0).tostring() == "5")
{
Response.Write("6");
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum