Solved

VB6 / ADO / MS Sql Server field name resolution.

Posted on 2000-02-13
8
258 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
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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now