How to refer to a column name on form "i.SomeColumn"?

  • Thread starter Thread starter K Viltersten
  • Start date Start date
K

K Viltersten

I have a data reader and it executes a query where
one of the joined tables is called Monkey,
containing a column called Donkey. One way to
refer to it is as follows (it's 5:th in order).

SqlDataReader dr = getBlobb();
bool b = dr.GetBoolean(5);

However, i'd like to use an other form, namely
reference by string. I've tried the following but
only got an error about index going cuckoo.

SqlDataReader dr = getBlobb();
bool b = (bool)dr["Monkey.Donkey"];

It usually works, when i don't have any dots in
the reference, so i'm suspecting it has to do
with it. Am i right? How to work it?
 
What if you just try "Donkey" ? The name to use is the name of the column
*in the result set*. For most if not all DBMS :
- columns are named using just the column name
- if you have conflicting name you have to use an alias

Table names are never used automatically to name a column in a resultset
(even when two names are in conflict).
 
What if you just try "Donkey"? The name to use
is the name of the column *in the result set*.
For most if not all DBMS :
- columns are named using just the column name
- if you have conflicting name you have to use
an alias

Table names are never used automatically to name
a column in a resultset (even when two names are
in conflict).

I basically didn't think of that... I expected
something less convenient, hehe. Thanks!
 
Back
Top