Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Help Understanding INNER JOIN

Reply
 
Old 09-10-2008   #1 (permalink)
Leona Leal Educator


 
 

Help Understanding INNER JOIN

I have this script that seems to work until;

rsSchools.Open "SELECT * FROM Schools INNER JOIN Students ON
Schools.StdntID=Students.StdntID", Cnnct, 3, 3

However when I go to reference a field it bombs!

On Response.Write rsSchools("StdntID") i get the following message!

ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name
or ordinal.

I know the join works because the rsSchools.RecordCount returns the right
number of records.

Why do I bomb on my Response.Write rsSchools("StdntID") ?

Thanks for the help in advance


Leona





My System SpecsSystem Spec
Old 09-10-2008   #2 (permalink)
hb21l6


 
 

Re: Help Understanding INNER JOIN


"Leona Leal Educator" <LeonaLealEducator@xxxxxx> wrote in
message news:9EB33F21-70FD-4041-BBD8-8DA86E72EB87@xxxxxx
Quote:

>I have this script that seems to work until;
>
> rsSchools.Open "SELECT * FROM Schools INNER JOIN Students ON
> Schools.StdntID=Students.StdntID", Cnnct, 3, 3
>
> However when I go to reference a field it bombs!
>
> On Response.Write rsSchools("StdntID") i get the following message!
>
> ADODB.Recordset (0x800A0CC1)
> Item cannot be found in the collection corresponding to the requested name
> or ordinal.
>
> I know the join works because the rsSchools.RecordCount returns the right
> number of records.
>
> Why do I bomb on my Response.Write rsSchools("StdntID") ?
>
> Thanks for the help in advance
>
>
> Leona
You have two tables with the same field name so it doesn't know which one to
return

try specifying the field names you require.
rsSchools.Open "SELECT Students.StdntID as studentID, Students.fieldName2
FROM Schools INNER JOIN Students ON
Schools.StdntID=Students.StdntID", Cnnct, 3, 3

etc

My System SpecsSystem Spec
Old 09-10-2008   #3 (permalink)
Old Pedant


 
 

RE: Help Understanding INNER JOIN



"Leona Leal Educator" wrote:
Quote:

> rsSchools.Open "SELECT * FROM Schools INNER JOIN Students ON
> Schools.StdntID=Students.StdntID", Cnnct, 3, 3
>
> On Response.Write rsSchools("StdntID") i get the following message!
> ADODB.Recordset (0x800A0CC1)
> Item cannot be found in the collection corresponding to the requested name
> or ordinal.
"hb" is absolutely correct as to the reason for the error and the solution.
But just as a general rule you should always give the explicit list of fields
you need in your SELECT. It would be highly unusual to actually *need* all
the field in both tables in your VBS code, and you can gain efficiency
(sometimes a lot) by only transferring needed data.

Having said all that...

It's also true that for *some* databases ADO will allow you to do
Response.Write rsSchools("Students.StdntID")
and separate the tables via the recordset field selector. Whether it works
or not depends on whether the SQL query to the given DB returns the table
info for each field or not.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
LINQ: Inner Join & Left Outer Join Q .NET General
Help understanding one liner VB Script
Understanding the WLM newsreader Live Mail
UAC problem - Need a little help and a lot of understanding Vista security
Understanding Vista Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46