Solved

VB6 / ADO / MS Sql Server field name resolution.

Posted on 2000-02-13
8
264 Views
Last Modified: 2013-12-25
Using ADO to connect to MS Sql Server from VB6 we access the names of fields in the following manner.

FieldName = rs.Fields(r&).Name

In our SQL queries we sometimes need to implicitly name the table with the field name especially where joins are concerned see example...

Select Person.FullName, Person.FirstName from Person etc....

The problem is that the table name is not returned in the fieldname as it is with many of the other backend databases that we are familiar with.

Is it possible to get the source table for each field in the recordset?

0
Comment
Question by:finster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 2517422
>get the source table
rs.Fields(1).SourceTable
0
 

Author Comment

by:finster
ID: 2517481
Which version of ADO is that? I cannot find it in the object library, and I know that this functioinality was in DAO and RDO.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2517605
field1 = rs(0).name

to get a value

just simply this

field2 = rs(0)

i don't really understand the question of what you need to be done.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:finster
ID: 2517912
In the sample query:

Select Person.FullName, Person.FirstName from Person

we need an ADO method that will return "Person" when queried. We can already get the FieldName, but we also want the Table Name of where that field came from.
0
 
LVL 15

Expert Comment

by:ameba
ID: 2518503
Sorry, that 'SourceTable' was DAO.
You can check properties collection of your field, e.g.
? rs.fields(1).Properties(1).name
BASETABLENAME

Depending on the provider, that property can have other name.
After checking property name, use something like
? rs.fields(1).Properties("BASETABLENAME").value
0
 

Expert Comment

by:vinoopauls
ID: 2519935
as ameba mentioned

rs.fields(1).Properties(1).name

gives the table name
 
0
 
LVL 15

Accepted Solution

by:
ameba earned 50 total points
ID: 2520840
No, it gives "BASETABLENAME" :)
Use .Value
0
 

Author Comment

by:finster
ID: 2521072
for this method, we found that

rs.fields(1).Properties(3).value

gave us what we wanted

Thanks to all
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question