变形金刚暗焰崛起双人:asp 显示数据库内容时如何将两个表连在一起?

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 14:58:17
如:有两个表:choose_course,student
其中choose_course表中有teachername ,studentid 字段,表student中也有studentid等字段
我想通过条件choose_course表中teachername='"+Session("teachername")+"' 并且studentid=(student表中studentid)
称想显示student表中符合上述条件的信息!请问具体要怎样写sql语句?

如查我想写成下面这样要怎样改呢?
<%
set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")
DBPath = Server.MapPath("../data.mdb")
dbconnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
'SQL="select * from student where studentid="+Session("studentid")+"
SQL="select * from choose_course,student where teachername='"+Session("teachername")+"' and

choose_course.studentid=student.studentid"
set mystu=dbconnection.execute(SQL)
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>myclass</title>
<style type="text/css">
<!--
body {
margin-top: 0px;
}
body,td,th {
font-size: 14px;
}
-->
</style></head>

<body>
<table width="618" border="0" align="center" bgcolor="#ffffcc">
<tr>
<td><font color="blue"><b>学号<b></font></td><td><font color="blue"><b>姓名<b></font></td><td><font

color="blue"><b>性别<b></font><td><td><font color="blue"><b><font color="blue"><b>学院<b></font></td><td><font

color="blue"><b>电话<b></font></td><td><font color="blue"><b>email<b></font></td><td><font color="blue"><b>生日

<b></font></td> </td>
</tr>
<% DO WHILE NOT myifo.EOF %>
<TR>
<td><% =mystu("studentid") %></td><td><% =mystu("studentname") %></td><td><% =mystu("sex") %><td><td><% =mystu

("collage") %></td><td><% =mystu("phonenumber") %></td><td><% =mystu("email") %></td><td><% =mystu("birthday") %

></td> </td>
</tr>
<% myifo.movenext
loop
%>
</table>
</body>
二楼的好像不行,还有我这里写错了点,<% DO WHILE NOT myifo.EOF %> 这里和下面的我已发现改正过来试了,再按二楼给的答案写上去还是不行啊!谁可以帮我解答.

"select * from choose_course,student where choose_course.studentid and student.studentid and teachername="+Session("teachername");