• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

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.
0
1jaws
Asked:
1jaws
  • 6
  • 6
2 Solutions
 
Aneesh RetnakaranDatabase 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
 
HainKurtSr. System AnalystCommented:
if (bool.Parse(reader["updated"].ToString()) == false)
-->
if (reader["updated"].ToString()) == "0") ....
0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
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
 
HainKurtSr. System AnalystCommented:
also, you can skip the first two by

dataReader.NextResult()
dataReader.NextResult()

0
 
1jawsAuthor Commented:
YEs thank you!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now