473,408 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Duplicate fieldnames in Datareader

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.
Nov 19 '05 #1
3 1971
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

"Beren" <be***@angband.me> wrote in message
news:xb*********************@phobos.telenet-ops.be...
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.

Nov 19 '05 #2
The simplest way is to access these fields (especially the
second DateCreated) by index.

Elton Wang
el********@hotmail.com
-----Original Message-----
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 bothvalues 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.
.

Nov 19 '05 #3
Thanks for the suggestions.
it's solved.

Thanks,

Beren
"Beren" <be***@angband.me> wrote in message
news:xb*********************@phobos.telenet-ops.be...
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.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
7
by: | last post by:
How do I get to the fieldnames of a table in a recordset? I have a recordset which I output into HTML. And on data from certian columns I need to perform different actions. I would like to...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
1
by: Jay Balapa | last post by:
Hello, Iam creating a query page, in which a Drop Down List will have collection of fieldnames. Is there a elegant way of doing it? Currently Iam opening up a datareader and using...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
1
by: Brent | last post by:
I'm having a hard time wrapping my head around how to build a multi-dimensional array of n length out of a DataReader loop. Take this pseudo-code: ======================================= public...
6
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ...
6
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using...
2
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.