Link to home
Start Free TrialLog in
Avatar of 1jaws
1jawsFlag for United States of America

asked on

easy for experts.

I have a sp that at the end I have this code
updated is bit and returnMessage is varchar
select @updated as updated, @returnMessage as message

but then on cs code I am using Execute Reader and using while loop to get the value of the updated and the message but gives me error saying {updated}
I say like this on while loop after executing reader
if (bool.Parse(reader["updated"].ToString()) == false)     -->> Catches error here.
...blah blah...

what am I doing wrong..?
I am trying to find the value of the updated and the of course message.
SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1jaws

ASKER

you are probably right on most cases but I have used that somewhere else before and it didnt catch error before. Anyhow, I think something else wrong here aneeshattingal because when I do that also doesnt like it at all..
lblChange.Text = reader["message"].ToString();   and error is on debug shows {message}  and message is varchar.. so something I am referencing wrong... should I use executescalar?
if (bool.Parse(reader["updated"].ToString()) == false)
-->
if (reader["updated"].ToString()) == "0") ....
Avatar of 1jaws

ASKER

no.. cannot convert string to bool.
in my post, I suggested you to use:

f (reader["updated"].ToString()) == "0") ....

probably from db, it is coming as 0, 1, not true or false
Avatar of 1jaws

ASKER

yes I know but it gives error saying it cannot convert string to bool...
and I guess right syntax is Boolean.Parse(...)
Avatar of 1jaws

ASKER

that didnt work either .. this worked if (reader["updated"].ToString() == "0") but  it is giving me IndexOutOFRangeException {updated}  
if (reader["updated"].ToString()) == "0") ....

in my last 2-3 posts I suggested NOT using bool.parse, and you keep saying boolean parse errors, AI am confused now... anyway, I guess you finally started using

if (reader["updated"].ToString() == "0")

;) now where do you get this index error? it should be somewhere else...
Avatar of 1jaws

ASKER

I am getting that index error because my sp I have three select statements, it is thinking first one which has no column name, thats why it is throwing error. Question is how can I ignore first two select statement but rather have the third select stament which contains, update and message column names see below
my results looks like this when I executed my sp

No column Name
1

ID
12232

updated     message
1                it is updated

as you can see I am getting three different resutls. but when I am reading from cs code I just want third result... Thats all I need.
how can we say something in this case?

you should post (at least related parts of) sp code and the vb/c# code to get the data from your sp

you can replace select statements in your sp
so updated will be first thing you read from cs?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 1jaws

ASKER

YEs thank you!