Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-17-2011, 08:15 AM   PM User | #1
abhiamity86
New to the CF scene

 
Join Date: Jun 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
abhiamity86 is an unknown quantity at this point
Database access related issue

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 .
abhiamity86 is offline   Reply With Quote
Old 07-11-2011, 11:00 AM   PM User | #2
kelvincostner
New to the CF scene

 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
kelvincostner is an unknown quantity at this point
Try this,

SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
if (dr(0).tostring() == "5")
{
Response.Write("6");
}
}
}
kelvincostner is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:59 AM.


Advertisement
Log in to turn off these ads.