Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi,

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).
How it is possible.
Pls help me out.

Thanks
Abhishek
Posted

C#
if (reader.HasRows)
        {
            while (reader.Read())
            {
                if(reader.GetInt32(0) == 5)
                 {
                         Label1.Text = 6;
                 }
            }
        }
 
Share this answer
 
Comments
abhiamity86 16-Jun-11 7:57am    
Thanks For Reply..
But sir it is giving exception Specified cast is not valid in if condition.
amit28august 16-Jun-11 8:41am    
dude u have check for the value coming from database....whether it is a integer or string...thats what the error says.....
abhiamity86 17-Jun-11 1:28am    
Pls sir Give me some sort of hint so that i can resolve this issue.
Thanks
Abhishek
try this:

C#
SqlDataReader dr = null;
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        if (dr.GetInt32(0) == 5)
                        {
                            Response.Write("6");
                        }
                    }
                }
 
Share this answer
 
Comments
abhiamity86 17-Jun-11 1:31am    
Again it is giving Same exception Specified cast is not valid .
Pls help me in resolving the issue.
Here dr is of tinyint type.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900