?
Solved

VB6 / ADO / MS Sql Server field name resolution.

Posted on 2000-02-13
8
Medium Priority
?
267 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 200 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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