如何在一个asp文件中两次或多次调用数据库?
我想调用同一个数据库的字段,比如:select*fromadminwherechk=0orderbyidasc和select*fromadminwherechk=1ord...
我想调用同一个数据库的字段,比如:
select * from admin where chk=0 order by id asc 和 select * from admin where chk=1 order by id asc
怎样关闭一个数据库然后用第二个? 展开
select * from admin where chk=0 order by id asc 和 select * from admin where chk=1 order by id asc
怎样关闭一个数据库然后用第二个? 展开
1个回答
展开全部
第一次调用完
用
rs.close关闭第一个连接
然后在调用第二次,例如
dim conn,connstr
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("db.mdb")
conn.Open connstr
set rs=server.createobject("adodb.recordset")
sql="select * from admin where chk=0 order by id asc"
rs.open sql,conn,1,3
……
rs.close
sql="select * from admin where chk=1 order by id asc"
rs.open sql,conn,1,3
……
rs.close
set rs=nothing
conn.close
set conn=nothing
如过需要在调用第一次时调用第二次只需要建立名称不同的两个对象就可以了,例如:
dim conn,connstr
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("db.mdb")
conn.Open connstr
set rs1=server.createobject("adodb.recordset")
sql1="select * from admin where chk=0 order by id asc"
rs1.open sql1,conn,1,3
set rs2=server.createobject("adodb.recordset")
sql2="select * from admin where chk=1 order by id asc"
rs2.open sql2,conn,1,3
……
rs1("字段")=rs2("字段")
rs1.close
rs2.close
set rs1=nothing
set rs2=nothing
conn.close
set conn=nothing
用
rs.close关闭第一个连接
然后在调用第二次,例如
dim conn,connstr
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("db.mdb")
conn.Open connstr
set rs=server.createobject("adodb.recordset")
sql="select * from admin where chk=0 order by id asc"
rs.open sql,conn,1,3
……
rs.close
sql="select * from admin where chk=1 order by id asc"
rs.open sql,conn,1,3
……
rs.close
set rs=nothing
conn.close
set conn=nothing
如过需要在调用第一次时调用第二次只需要建立名称不同的两个对象就可以了,例如:
dim conn,connstr
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("db.mdb")
conn.Open connstr
set rs1=server.createobject("adodb.recordset")
sql1="select * from admin where chk=0 order by id asc"
rs1.open sql1,conn,1,3
set rs2=server.createobject("adodb.recordset")
sql2="select * from admin where chk=1 order by id asc"
rs2.open sql2,conn,1,3
……
rs1("字段")=rs2("字段")
rs1.close
rs2.close
set rs1=nothing
set rs2=nothing
conn.close
set conn=nothing
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询