当前位置:编程学习 > asp >>

asp运行时出现的错误:ASP服务器发现运行时错误: 错 误 码:0x80040E14 错误代码:conn.Execute(strSql)

Dim sqlA,sqlB,strSql,username,usermail sqlA="Insert Into tbBbs(strTitle,intLayer,intFatherId,intChild,intHits,strIP,username,dtmSubmit,intForumId" sqlB = "Values('" & strTitle & "'," & intLayer & "," & intFatherId & "," & intChild & "," & intHits & ",'" & strIP & "','" & username & "',#" & Now() & "#," & intForumId If strBody<>"" Then '如果有内容,则添加 sqlA = sqlA & ",strBody" sqlB = sqlB & ",'" & strBody & "'" End If If strEmail<>"" Then '如果有E-mail,则添加 sqlA = sqlA & ",usermail" sqlB = sqlB & ",'" & usermail & "'" End If strSql = sqlA & ") " & sqlB & ")" conn.Execute(strSql) '下面将该栏目的文章数加1 strSql="Update tbForum Set lngForumCount=lngForumCount+1 Where ID = " & intForumId conn.Execute(strSql) '下面将该用户的发表文章数加1 strSql="Update user Set intArticle=intArticle+1 Where username='" & Session("username") & "'" conn.Execute(strSql) '关闭对象 conn.Close Set conn=Nothing '重定向回BBS列表页,请记住再将当前栏目号码传递回去。 Response.Redirect "bbs_list.asp?intForumId=" & Request.Form("txtForumId") End If
答案:不同情况语句不一样,你做了判断。把strSql这个字符串response.write strSql 输出看看语句是否正确。问题可能出在Values 左右你没有空格,语句是错误的。
其实这种情况你可以这么写更好:
SQL = ""
SQL = SQL & "Insert Into tbBbs "
SQL = SQL & "("
SQL = SQL & "strTitle,"
SQL = SQL & "intLayer,"
SQL = SQL & "intFatherId,"
SQL = SQL & "intChild,"
SQL = SQL & "intHits,"
SQL = SQL & "strIP,"
SQL = SQL & "username,"
SQL = SQL & "dtmSubmit,"
If strBody<>"" Then SQL = SQL & "strBody,"
If strEmail<>"" Then SQL = SQL & "usermail,"
SQL = SQL & "intForumId"
SQL = SQL & ") "
SQL = SQL & "Values "
SQL = SQL & "("
SQL = SQL & "'" & strTitle & "',"
SQL = SQL & "'" & intLayer & "',"
SQL = SQL & "'" & intFatherId & "',"
SQL = SQL & "'" & intChild & "',"
SQL = SQL & "" & intHits & ","
SQL = SQL & "'" & strIP & "',"
SQL = SQL & "'" & username & "',"
SQL = SQL & "'" & dtmSubmit & "',"
If strBody<>"" Then SQL = SQL & "'" & strBody & "',"
If strEmail<>"" Then SQL = SQL & "'" & strEmail & "',"
SQL = SQL & "'" & intForumId & "'"
SQL = SQL & ")"
==========================
字段哪个是数字类型,就不加单引号了,我不知道,你自己在调整一下。intHits 这个点击数应该是数字,我没加单引号。用于判断的字段别放在最后,不然总是有逗号的影响,所以最后那个字段我把intForumId 放在了最后。
其他:把sql语句分开来写吧,虽然效率会低那么一点点。
你这样写,sql语句很分散,很容易出错的。
你可以先把前面几个添加进去,再获取这条记录集,再判断是否为空,决定更新数据。

上一个:在asp正则表达式中如何匹配指定范围内的字符
下一个:用asp 登陆网页代码。。急

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,