帮我看看我的ASP+Access代码怎么写数据库失败。
帮我看看我的ASP+Access代码怎么写数据库失败。
连接数据库
<%
DB="data/#qqip.asp"
Response.Buffer=True
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if fso.FolderExists(server.MapPath("include"))=false then
DB="../"&DB
lk="../"
end if
set fso=nothing
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DB)
conn.Open connstr
copycolor="#A9A9A9"
%>
表单:
</TABLE>
<form name="mytuijian" action="user_addsave.asp" method="post">
<TABLE width="95%" border="0" cellpadding="0" cellspacing="0" style="BORDER-RIGHT: #b1bfee 1px solid; BORDER-TOP: #b1bfee 1px solid; BORDER-LEFT: #b1bfee 1px solid; BORDER-BOTTOM: #b1bfee 1px solid">
<TBODY>
<TR vAlign=center align=left>
<TD width="10%" height=35> <FONT color=#ff0000>* </FONT>产品名称:<font color="#FF0000"> </font>
</TD>
<TD width="53%"><input name="tuijianname" type="text" class=regtxt id="tuijianname" maxlength="30"> </TD>
</TR>
写数据库:
<!--#include file="include/dianmeng.asp" -->
sqltuijian = "select * from tuijian"
set rs=Server.Createobject("ADODB.RecordSet")
rs.open sqltuijian,conn,1,3
rs("UserId")="aaa123"
rs("tuijianname")=left(request.form("tuijianname"),30)
rs("tuijianjg")=request.form("tuijianjg")
rs("tuijiantp")=request.form("tuijiantp")
rs("tuijiandz")=request.form("tuijiandz")
rs("tuijianjj")=left(request.form("tuijianjj"),50)
exec="insert into tuijian(UserId,tuijianname,tuijianjg,tuijiantp,tuijiandz,tuijianjj)values('"+UserId+"','"+tuijianname+"','"+message+"')"
rs.close
set rs = nothing
conn.close
set conn=nothing
response.write "<script language='javascript'>"
response.write "alert('添加成功,您已经添加了一个产品!');"
response.write "location.href='';"
response.write "</script>"
end if
%>
答案:<%
on error resume next
referer = request.ServerVariables("HTTP_REFERER")
rUserId = Trim(request("userId"))
rTuiJianName = Trim(request("tuijianname"))
rTuiJianJG = Trim(request("tuijianjg"))
rTuiJianDZ = Trim(request("tuijianDz"))
rTuiJianTP = Trim(request("tuijiantp"))
rTuiJianZT = Trim(request("tuijianzt"))
rTuiJianJJ = Trim(request("tuijianJJ"))
insertSql = "insert into [tuijian]("
insertSql = insertSql & "[userId]"
insertSql = insertSql & ",[tuijianname]"
insertSql = insertSql & ",[tuijianjg]"
insertSql = insertSql & ",[tuijiandz]"
insertSql = insertSql & ",[tuijiantp]"
insertSql = insertSql & ",[tuijianzt]"
insertSql = insertSql & ",[tuijianjj]"
insertSql = insertSql & ") values ("
insertSql = insertSql & "'" & rUserId & "'"
insertSql = insertSql & ",'" & rTuiJianName & "'"
insertSql = insertSql & "," & rTuiJianJG
insertSql = insertSql & ",'" & rTuiJianTP & "'"
insertSql = insertSql & ",'" & rTuiJianDZ & "'"
insertSql = insertSql & "," & rTuiJianZT
insertSql = insertSql & ",'" & rTuiJianJJ & "'"
insertSql = insertSql & ")"
conn.execute(insertSql)
conn.close
set conn = nothing
if err then
err.clear
response.write("<script type='text/javascript'>alert('对不起,添加失败!');history.back();</script>")
else
response.write("<script type='text/javascript'>alert('恭喜,添加成功!');location.href='" & referer & "';</script>")
end if
%>
其他://并且程序停止执行(这里是问题所在!)下面的操作没有执行,数据库当然没你要注册好的代码我发几个给你,完全免费和完整,不过要记得先给分 sqltuijian = "select * from tuijian"
set rs=Server.Createobject("ADODB.RecordSet")
rs.open sqltuijian,conn,1,3
rs.addnew
rs("UserId")="aaa123"
rs("tuijianname")=left(request.form("tuijianname"),30)
rs("tuijianjg")=request.form("tuijianjg")
rs("tuijiantp")=request.form("tuijiantp")
rs("tuijiandz")=request.form("tuijiandz")
rs("tuijianjj")=left(request.form("tuijianjj"),50)
exec="insert into tuijian(UserId,tuijianname,tuijianjg,tuijiantp,tuijiandz,tuijianjj)values('"+UserId+"','"+tuijianname+"','"+message+"')"
rs.update
rs.close
set rs = nothing
conn.close
set conn=nothing
你没有写"rs.addnew"和"rs.update",当然不能执行,还有就是检查相应的数据库文件夹权限,确保文件夹的写入权限已经开启!
上一个:Access 2000 数据库文件内容无法更改,知道的朋友来看看,如何解决.
下一个:兄弟们帮帮忙了,网页制作,ASP + ACCESS,数据库中文乱码问题!