Joining two tables with fields that have the same names
- From: "Monty" <monty@xxxxxxxxxxxxxxxx>
- Date: Wed, 23 May 2007 18:04:37 -0400
[post re-directed here from sqlserver.programming]
Hi all,
I'm joining two tables that have some of the same field names, like so:
ParentTable
ID
Note
DateCreated
ChildTable
ID
ParentID
Note
DateCreated
I then retrieve this data in a SQLDataReader (Using VB2005, .Net 2.0, MS
SQL 2000) using a statement like this:
SELECT C.*, P.* FROM ChildTable
INNER JOIN ParentTable P ON C.ParentID = P.ID
In ADO.Classic, I could specify which table and field I wanted in a
recordset like so:
oRecordSet("P.Note")
However in the .Net world with a SQLDataReader (at least when I tried last
time), it would not let me access the field like so:
oDataReader("P.Note")
I could only specify the field name, not the table name. It seems we are
taking a step back with ADO.Net in this particular case, unless I'm wrong. I
know I can specify a field name in my SQL like so "SELECT C.Note as
ChildNote", but I have some other considerations that make that impractical
in this case. I also know I can specify the index of the columns, but I
anticipate there will be changes in my table structure in the future and
don't want to have to re-work this part each time. I also am aware that
typically one would want to restrict your query results to the smallest
group of fields necessary, but in this case I need pretty much all of them
and the other considerations I mentioned above make it difficult to
specify all of them. I'm really hoping someone will point out that I'm wrong
and that it is possible to specify "TableName.FieldName".
Thanks in advance!
.
- Follow-Ups:
- Re: Joining two tables with fields that have the same names
- From: Bob Barrows [MVP]
- Re: Joining two tables with fields that have the same names
- Prev by Date: Re: Non traditional database connections and datasets
- Next by Date: Re: Joining two tables with fields that have the same names
- Previous by thread: Re: Non traditional database connections and datasets
- Next by thread: Re: Joining two tables with fields that have the same names
- Index(es):
Relevant Pages
|
|