fetching boolean value from sql query result

  • Thread starter Thread starter Daves
  • Start date Start date
D

Daves

trying to get a boolean value from DataReader (that is, result from a SQL
query);

boolean MyBool = MyDataReader.GetBoolean(3);

well it works using that number 3 but of course I would like to do something
like
... = MyDataReader.GetBoolean["IsLocked"];

since I don't always know the field number of the IsLocked field. Why is
this so complicated and what is the best solution??
 
Try

.... = MyDataReader.GetBoolean(MyDataReader.GetOrdinal("IsLocked"));

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
thx this works 100%
But why does ADO make it so complex to use DataReader["fieldname"] for
fetching the field values? It is as if it wants me by default to get them by
DataReader(field number) but this field number could so easily change if the
sql query is changed and ... an error would be produced. Am I missing
something?


Kai Brinkmann said:
Try

... = MyDataReader.GetBoolean(MyDataReader.GetOrdinal("IsLocked"));

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no
rights.


Daves said:
trying to get a boolean value from DataReader (that is, result from a SQL
query);

boolean MyBool = MyDataReader.GetBoolean(3);

well it works using that number 3 but of course I would like to do
something like
... = MyDataReader.GetBoolean["IsLocked"];

since I don't always know the field number of the IsLocked field. Why is
this so complicated and what is the best solution??
 
ok think I got it. What I needed to do was casting and use the casting
correctly, seems I used int where should have been int32 for example...

Daves said:
thx this works 100%
But why does ADO make it so complex to use DataReader["fieldname"] for
fetching the field values? It is as if it wants me by default to get them
by DataReader(field number) but this field number could so easily change
if the sql query is changed and ... an error would be produced. Am I
missing something?


Kai Brinkmann said:
Try

... = MyDataReader.GetBoolean(MyDataReader.GetOrdinal("IsLocked"));

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no
rights.


Daves said:
trying to get a boolean value from DataReader (that is, result from a
SQL query);

boolean MyBool = MyDataReader.GetBoolean(3);

well it works using that number 3 but of course I would like to do
something like
... = MyDataReader.GetBoolean["IsLocked"];

since I don't always know the field number of the IsLocked field. Why is
this so complicated and what is the best solution??
 
Back
Top