请帮我解决一个asp+sql的连接问题,在线等待!!!

一个问题是当我要用asp 访问两个表a,b时,a中用于保存学生基本信息如id,name;b中用于保存其他信息如地址,email,两者用一个索引关联。添加,修改,删除,查询怎么实现呢?我的代码如下:

 1   
 2Set Conn=Server.CreateObject("ADODB.Connection")   
 3Conn.Open"filedsn=D:\Program Files\Common Files\odbc\Data Sources\mydata.dsn;uid=wql;pwd=332721"   
 4Set rs=server.CreateObject("adodb.recordset")   
 5sql="select t1.id as id, name, tel, add from t1 inner join t2 on t1.id=t2.id where t1.id=1 "   
 6rs.open sql,conn,1,1   
 7do while not rs.eof   
 8response.write(rs("id"))   
 9response.write(rs("name"))   
10response.write(rs("tel"))   
11response.write(rs("add"))   
12rs.movenext   
13loop   
14rs.close   
15conn.close   
1<title>读出</title>

wangqili,you are very good!!!!!

出现如下错误“
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E21)
/wang/www6.asp, 第 6 行
请大家给我帮帮忙!!!!

---------------------------------------------------------------

看看这个吧,你连接的时候出问题了。

MS SQL Server数据库连接

用DSN连接:

1   
2set conn = Server.CreateObject("ADODB.Connection")   
3conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"   

不用DSN连接:

1   
2Set conn = Server.CreateObject("ADODB.Connection")   
3DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename"   
4conn.open DSNtemp   

---------------------------------------------------------------

sql="select t1.id as id, t1.name, t1.tel, t1.add from t1 inner join t2 on t1.id=t2.id where t1.id=1 "

试下,你的语应该不出错吧,加一个前缀试下

另外,你的2表有数据没有?
---------------------------------------------------------------

数据库连接有问题。

1   
2dim conn,DBPath   
3Set conn = Server.CreateObject("ADODB.Connection")   
4DBPath = Server.MapPath("class.mdb")   
5conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath&";password=983.pwd.-;"   

看看行否。
---------------------------------------------------------------

你先这样,用最简单的查询看看能否脸上数据库:

Set rs=server.CreateObject("adodb.recordset")
sql="select id from t1"
rs.open sql,conn,1,1
do while not rs.eof
response.write rs("id")&

1<br/>

rs.movenext
loop

如果能显示出id,说明数据库连接没有问题,那就是rs打开的问题了

---------------------------------------------------------------

如果上面的步骤说明数据库连接没错,那么后面的程序改成这样试试:

Set rs=server.CreateObject("adodb.recordset")
sql="select t1.id as id, t1.name as name, t2.tel as tel, t2.add as add from t1,t2 where t1.id=t2.id and t1.id=1 "
rs.open sql,conn,1,1
---------------------------------------------------------------

仔细检查一下SQL语句
在查询分析器里试验一下,看有没有问题,如果没问题的话
那估计就是你连接有问题
用OLE连接试试

Published At
Categories with Web编程
comments powered by Disqus