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.
1jawsAsked:
Who is Participating?
 
HainKurtConnect With a Mentor Sr. System AnalystCommented:
also, you can skip the first two by

dataReader.NextResult()
dataReader.NextResult()

0
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
SQL bit fields stores 0 or 1 and not true / false.
0
 
1jawsAuthor Commented:
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?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
HainKurtSr. System AnalystCommented:
if (bool.Parse(reader["updated"].ToString()) == false)
-->
if (reader["updated"].ToString()) == "0") ....
0
 
1jawsAuthor Commented:
no.. cannot convert string to bool.
0
 
HainKurtSr. System AnalystCommented:
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
0
 
1jawsAuthor Commented:
yes I know but it gives error saying it cannot convert string to bool...
0
 
HainKurtSr. System AnalystCommented:
and I guess right syntax is Boolean.Parse(...)
0
 
1jawsAuthor Commented:
that didnt work either .. this worked if (reader["updated"].ToString() == "0") but  it is giving me IndexOutOFRangeException {updated}  
0
 
HainKurtSr. System AnalystCommented:
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...
0
 
1jawsAuthor Commented:
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.
0
 
HainKurtSr. System AnalystCommented:
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?
0
 
1jawsAuthor Commented:
YEs thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.