注册 登录
编程论坛 ASP技术论坛

如何调用数据库俩个表的信息。

罗林鹏 发布于 2010-09-09 10:32, 611 次点击
我的一个页面想调用数据库两个表的信息,但是这俩表中字段有重复,所以那个sql语句好像写错了,应该怎么写啊。
select b.sheng as sheng,b.shi as shi,b.xian as xian,c.lxr as lxr,c.khmc as khmc,c.sj as sj from khxxb b,khhtb c where b.kh_id = c.kh_id
这个是我的那个sql语句,帮看下,是不是错了 提示
:错误类型:
ADODB.Field (0x80020009)
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/web/LlP_JACK/fangyingdui/qbkhxx.asp
,数据库有记录啊。 郁闷中····
4 回复
#2
yms1232010-09-09 13:18
表结构是什么样?到底要查询什么数据?
#3
罗林鹏2010-09-09 13:58
表结构就是一个tr- -,有 a , b 来个表, 从a里面查一条信息,再从b里面查一条信息。然后显示在一起。 但是这俩表中字段有重复的。
#4
wangjy5002010-09-09 18:44
from khxxb b,khhtb c
改成:
from khxxb as b,khhtb as c
#5
a1900662010-09-13 00:09
回复 楼主 罗林鹏
我现在就是用这方法读入多个表,供你参考:
<%
 if request("dj")<>"" then
sql="select * from users1 where userid="&request("dj")&" order by id asc"
else
sql="select * from users1  order by id asc"'第1表
end if
 Set rs= Server.CreateObject("ADODB.Recordset")
 rs.open sql,conn,1,1
 
set rs1=server.createobject("adodb.recordset")'第2表
sql1="select * from users2 order by id asc"
rs1.open sql1,conn,1,1

set rs2=server.createobject("adodb.recordset")'第3表sql1="select * from users3 where mtype='2010' and question order by id asc"
rs2.open sql1,conn,1,1
 
  if rs.eof and rs.bof then
       response.write "<p align='center'> 还 没 有 任 何 记 录</p>"
   else
      totalPut=rs.recordcount
      totalPut=rs.recordcount
      if currentpage<1 then
          currentpage=1
      end if
      if (currentpage-1)*MaxPerPage>totalput then
       if (totalPut mod MaxPerPage)=0 then
         currentpage= totalPut \ MaxPerPage
       else
          currentpage= totalPut \ MaxPerPage + 1
       end if

      end if
       if currentPage=1 then
           showpage totalput,MaxPerPage,"index.asp"
            showContent
            showpage totalput,MaxPerPage,"index.asp"
       else
          if (currentPage-1)*MaxPerPage<totalPut then
            rs.move  (currentPage-1)*MaxPerPage
            dim bookmark
            bookmark=rs.bookmark
           showpage totalput,MaxPerPage,"index.asp"
            showContent
             showpage totalput,MaxPerPage,"index.asp"
        else
            currentPage=1
           showpage totalput,MaxPerPage,"index.asp"
           showContent
           showpage totalput,MaxPerPage,"index.asp"
          end if
       end if
   end if
   sub showContent
       dim i
       i=0

  %>
<%do while not rs.eof%>
<%=rs("userid")%>  <%=rs1("userid")%> <%=rs2("userid")%>

<% i=i+1
          if i>=MaxPerPage then exit do
               rs.movenext'第一表,注意rs和下面的rs1
              rs1.movenext'第二表
              rs2.movenext'第三表
       loop
%>



1