Duplicate fieldnames in Datareader

B

Beren

Hello,

I have an sproc to query a couple of tables, that have the same fieldnames,
for example DateCreated.

-------------------------------------
Select a.* , b.* From tablea a
Join table b On b.keyfield = a.keyfield
-------------------------------------

Now table A and B both have a field called "DateCreated", and I need both
values in my application.

-------------------------------------
.....-- New DataReader dr --....
.....-- query --....
DateCreatedA = dr.Item("a.DateCreated")
DateCreatedB = dr.Item("b.DateCreated")
-------------------------------------

Doesn't seem to work, but

-------------------------------------
SomeVariable = dr.Item("DateCreated")
-------------------------------------

does work, but only for one value...

When I check the resultset in Query Analyzer, it shows duplicate fieldnames,
so that's probably why the DR doesn't swallow my brave attempts with
"a.DateCreated" and "b.Da..."

Can someone help me out getting both values ?

Beren.
 
W

William F. Robertson, Jr.

Beren,

It really isn't good design to have * pulled from a table. You should also
give each returning column a unique name. Otherwise it will pull the first
occurrece when you use dr.Item("DateCreated").

All the columns are in there.

for i = 0 to dr.FieldCount
Response.Write( dr.GetName( i ) )
next

it will list all the field names and show two for DateCreated.

So you could reference each of the DateCreated columns by using the ordinal.

HTH,

bill
 
E

Elton Wang

The simplest way is to access these fields (especially the
second DateCreated) by index.

Elton Wang
(e-mail address removed)
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top