Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 7th, 2006, 06:12 AM
Authorized User
 
Join Date: Jan 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql statement doubt

Hi,

How do you write sql statements for joining two tables
say

[u]Program</u>
PID
PNAME
DESC


[u]STUDENTS</u>
SID
SNAME
EMAIL
PWD
PID

how do i join these two tables using sql statements.here PID is the unique key among them.I know this statement.
select * from program,students where program.PID=students.PID

but my question is how do i use join statements for this.
I only want to display Pname from program table and every fields from students table.

and after creating sql statement how do i use datareader to access these values from two tables.
Normally i do for one table like this

while dr.read

response.write(dr("SNAME").tostring())
response.write(dr("SID").tostring())
response.write(dr("EMAIL").tostring())
response.write(dr("PWD").tostring())
end while

but in this case where i am joining two tables,how do i use dreader to do that.
ie.
response.write(dr("?").tostring())--??? what is it.
Please give me an answer as soon as possible
 
Old February 8th, 2006, 05:33 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 112
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The SQL to join (INNER JOIN) the two related tables is:

Code:
SELECT STUDENTS.SID, STUDENTS.SNAME, STUDENTS.EMAIL, STUDENTS.PWD, STUDENTS.PID, PROGRAM.PNAME
FROM STUDENTS INNER JOIN PROGRAM ON STUDENTS.PID = PROGRAM.PID;
As for data reader, I've never used it. But, I assume you have to specify the source of the records. In that case you would use the SQL above as the source or create a Query or stored procedure to output the records...

 
Old February 8th, 2006, 01:27 PM
Authorized User
 
Join Date: Jan 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Tell me how to specify these in the datareader.if anybody knows pls tell me.






Similar Threads
Thread Thread Starter Forum Replies Last Post
convert a SQL Statement from MS Access to a SQL Corey Access 6 March 28th, 2007 12:33 PM
SQL Statement??? carswelljr SQL Server 2000 2 August 25th, 2006 12:40 PM
SQL Statement rylemer SQL Language 3 October 21st, 2005 09:07 PM
SQL Statement help johnman Access 1 October 22nd, 2004 10:20 AM
SQL Statement stu9820 ASP.NET 1.0 and 1.1 Basics 1 September 30th, 2003 04:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.