asp添加.access

来源:百度知道 编辑:UC知道 时间:2024/05/13 19:50:11
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("mdb.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
set rs= Server.CreateObject("adodb.recordset")
conn.open connstr

username=Trim(request.form("username"))
userpwd=Trim(request.form("userpwd"))
ps=Trim(request.form("ps"))

dim sql
sql="select * from table where (id is null)"
rs.open sql,conn,1,3
rs.addnew

rs("username")=username
rs("userpwd")=userpwd
rs("ps")=ps

rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write "<script language='javascript'>"
response.write "alert('tianjiachenggong!');"

语法没错,不过Microsoft Access Driver 不稳定,支持也不好,用标准SQL语法就不会了.

dim sql
sql="select * from table where (id is null)"
rs.open sql,conn,1,3
rs.addnew

rs("username")=username
rs("userpwd")=userpwd
rs("ps")=ps

rs.update
rs.close
改为:
conn.execute"insert into table (username,userpwd)values('"&username&"','"&userpwd&"')"

你都没有写提示什么错误
如果有错误应该是conn
你的conn定义放到第一行应该没有问题了

sql="select * from table where (id is null)"
如上所示,你资料库中,确定要添加的表是table吗?

另资料库连接,不妨这样写
<%
Dim conn,connstr
set conn=Server.CreateObject("ADODB.Connection")
connstr="Driver={Microsoft Access Driver (*.mdb)};DBQ="&Server.MapPath("mdb.mdb")'注意这裏是哟(纲页文件与资料库是否在同一目录下)
conn.Open connstr
%>