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

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?
 
P

Patrice

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).
 
K

K Viltersten

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top