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

[求助 ASP]有两个数据库,把数据库B的列出的值等于数据库A的某个值

calnlao 发布于 2010-04-04 17:40, 619 次点击
[求助 ASP]有两个数据库,把数据库B的列出的值等于数据库A的某个值


数据库:B        表:user_chare

序列号 所属帐号  用户
 001   0000000  adasas

数据库:B  表:user_chare  的 所属帐号 等于 数据库:A   表:user_name 的  帐号

该怎么实现呢?我想用ASP程序实现它

小弟感谢~~~~

PS:这是一个游戏数据库。


[ 本帖最后由 calnlao 于 2010-4-4 17:47 编辑 ]
5 回复
#2
nicechlk2010-04-05 13:11
方法:采用嵌套循环模式
'先获取A表里的user_name账号(遍历循环)
dim rs
set rs=conn.execute ("select user_name from A")
if not (rs.eof and rs.bof) then '如果账号存在
    do while not rs.eof   ’循环开始
    dim A_name
    A_name=rs("user_name")
    dim rs1
    set rs1=conn.execute ("select * from user_name where 账号='"&A_name&"'") '用A的账号作为查询条件在B表里查询;
    if not rs1.eof then   ’如果存在
        do while not rs1.eof   '如果B表有多个账号对应,则再执行循环查询;
            dim B_name
            B_name=rs1("user_name")
            response.write B_name   ’输出结果
        rs1.movenext
        loop
    else
        response.write "对不起,您所查询的账号不存在!"
    end if
    rs1.close
    set rs1=nothing
rs.movenext
loop
rs.close
set rs1=nothing
你看看行不行?

[ 本帖最后由 nicechlk 于 2010-4-5 13:13 编辑 ]
#3
calnlao2010-04-05 17:54
谢谢你
这问题困扰了我很多天了
查资料也没成功
我现在正在修改中
在此感谢你
#4
calnlao2010-04-05 20:04
现在我想做个分页,但是却不会执行每页的指定数
程序代码:
<%@language=vbscript codepage=936 %>
<!--#include file="../include/nAdminCheck.asp"-->
<%ConnPath="../../"%>
<!--#include file="../include/youxiconn.asp"-->
<!--#include file="../include/function.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../include/sys.css" rel="stylesheet" type="text/css">
<head>
<title>信息管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../include/pageturn.js"></script>
</head>
<body>
<div align="center" class="title"><b><font color="#FFFFFF"><br>

 用户信息管理</font></b></div>
  <br>
  <table width="100%"  border="0" align="center" cellpadding="0" cellspacing="2">
      <tr>
      <td height="20" align="center" bgcolor="f2f2f2">
      <table border="0" cellspacing="0" cellpadding="0">
    <form name="form1" method="get" action="userjiaose.asp">
    <tr>
    <td width="72" align="right">角色名:</td>
    <td width="131" >
    <input name="keyword" type="text" class="textinput" id="keyword" value="<%=keyword%>" size="20">
    </td>
    <td width="155" align="center">输入角色名字进行搜索</td>
    <td width="50">
    <input type="submit" name="Submit" value="检索">
    </td>
    <td width="310">&nbsp;</td>
    <td width="198">&nbsp;</td>
    </tr>
    </form>
    </table>
      </td>
    </tr>
      </table>
  <br>
<div align="center">
<%
      keyword
=request("keyword")
      
set rs=server.createobject("adodb.recordset")
sql
="select user_no,character_no,character_name,wLevel,logout_time,dwMoney from [user_character] where 1=1"
   
if request("keyword")<>"" then
    sql
=sql&" and character_name like '%"&keyword&"%'"
   
end if
   sql
=sql&" order by user_no asc"
    rs.open sql,conn2,
1,1
    rs.PageSize
=20
  
IF rs.Eof THEN
   Response.Write(
"<div align=center><font><H2>数据库里没有对应的数据存在!</font></div>")
   
ELSE
%>
<form name="del" method="Post" action="delejiaose.asp" onSubmit="return ConfirmDel();">
  <table width="100%" border="0" cellpadding="5" cellspacing="1"  class="TABLEresult" align="center">
  <tr class="head">
    <td height="25" align="center" background="../include/sys.gif">&nbsp;</td>
    <td height="25" align="center" background="../include/sys.gif"><b>序列号</b></td>
    <td width="15%" align="center" background="../include/sys.gif"><b>所属帐号</b></td>
    <td width="17%" align="center" background="../include/sys.gif"><b>用户角色</b></td>
    <td width="6%" align="center" background="../include/sys.gif"><b>等级</b></td>
    <td width="18%" align="center" background="../include/sys.gif"><b>下线时间</b></td>
    <td width="11%" align="center" background="../include/sys.gif"><b>身上金钱</b></td>
    <td width="10%" align="center" background="../include/sys.gif"><b>操 作</b></td>
  </tr>
<%
   
If Request("mypage")="" Then
       rs.absolutepage
= 1
       inAbsolutePage
=1
   
Else
         rs.AbsolutePage
= cint(Request("mypage"))
       inAbsolutePage
=cint(Request("mypage"))
   
End If
   
For i=1 to rs.PageSize
   
do while not rs.eof   '循环开始
    dim A_name
    A_name
=rs("user_no")
   
dim rs1
   
set rs1=conn3.execute ("select * from user_profile where user_no='"&A_name&"'") '用A的账号作为查询条件在B表里查询;
    do while not rs1.eof   '如果B表有多个账号对应,则再执行循环查询;
    dim B_name
    B_name
=rs1("user_id")
%>
    <tr class='Tr' onMouseOver="this.style.backgroundColor='#C6EBDE'" onMouseOut ="this.style.backgroundColor=''">
    <td width="4%" align='center' bgcolor="#E2EEFE"><p><br>
    </p></td>
        <td width="19%" align='center' bgcolor="#E2EEFE"><%=rs("character_no")%></td>
        <td align='center'  bgcolor="#E2EEFE"><%=B_name%></td>
        <td align='center'  bgcolor="#E2EEFE"><%=rs("character_name")%></td>
        <td align='center'  bgcolor="#E2EEFE"><%=rs("wLevel")%></td>
        <td align='center'  bgcolor="#E2EEFE"><%=rs("logout_time")%></td>
        <td align='center'  bgcolor="#E2EEFE"><%=rs("dwMoney")%></td>
        <td align='center' bgcolor="#E2EEFE"><a href="modifjiaose.asp?character_no=<%=rs("character_no")%>&character_name=<%=rs("character_name")%>">修改</a><a href="delejiaose.asp?character_no=<%=rs("character_no")%>" onClick="return confirm('您确定进行删除操作吗?')"> 删除</a></td>
    </tr>
<%
    rs1.movenext
  
loop
   rs.movenext
  
loop
   
if rs.EOF then exit for
Next
%>
</table> </form>
<%
    mypage()
    rs.close
  
set rs1=nothing
  
set rs=nothing
END IF
%>
</div>
</body>
</html>


 
#5
nicechlk2010-04-06 19:03
程序代码:
<%sql1="select * from news"
set rs=server.CreateObject("adodb.recordset")
rs.open sql1,conn,
1,1
rs.pagesize
=num
page
=rs.pagesize
if curpage="" then
  curpage
=1
end if
rs.absolutepage
=curpage
if curpage=1 then
    response.Write
"首页"
else
    response.Write
"<a href='?curpage=1&BigClassName="&BigName&"&SmallClassName="&SmallName&"'>首页</a>"
end if
if curpage=1 then
    response.Write
"&nbsp;&nbsp;上一页"
else
    response.Write
"&nbsp;&nbsp;<a href='?curpage="&curpage-1&"&BigClassName="&BigName&"&SmallClassName="&SmallName&"'>上一页</a>"
end if
if rs.pagecount<curpage+1 then
    response.Write
"&nbsp;&nbsp;下一页"
else
    response.Write
"&nbsp;&nbsp;<a href='?curpage="&curpage+1&"&BigClassName="&BigName&"&SmallClassName="&SmallName&"'>下一页</a>"
end if
if rs.pagecount<curpage+1 then
    response.Write
"&nbsp;&nbsp;尾页&nbsp;&nbsp;"
else
    response.Write
"&nbsp;&nbsp;<a href='?curpage="&rs.pagecount&"&BigClassName="&BigName&"&SmallClassName="&SmallName&"'>尾页</a>&nbsp;&nbsp;"
end if
response.Write
"&nbsp;&nbsp;&nbsp;<font color='000000'>第"&curpage&"页&nbsp;&nbsp;共"&rs.pagecount&"页&nbsp;&nbsp;总共 "&rs.recordcount&" 条</font><font color='#cc0000'>"
if BigName="" and SmallName="" then
    response.Write
"<font color='#000000'>记录</font>"
else
   
if BigName="" or (BigName<>"" and SmallName<>"") then
        response.Write
""&SmallName&"】<font color='#000000'>记录</font>"
   
else
        response.Write
""&BigName&"】<font color='#000000'>记录</font>"
   
end if
end if
response.Write
"&nbsp;<font color='#000000'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;按 <font color='#CC3300'>"&page&"条/页</font> 显示</font>"
rs.close
set rs=nothing
rssit.close
%>
我一般用这种方式分页,你可以参考一下。
#6
calnlao2010-04-06 20:11
谢谢啦
我把
do while .....
 .....  
loop  代码给改了下

IF ... Then
.....

END IF

因为我的分页是封装了的


1