数据库写入错误,不知道哪里出了问题!

flybird99 2004-11-26 09:11:18
dim article_title,article_content,article_class,article_author,IncludePic,article_image,article_key
article_class=trim(request("article_class"))
article_title=trim(request("title"))
article_content=Server.HTMLEncode(request("content"))
IncludePic=trim(request("IncludePic"))
article_author=trim(request("author"))
article_image=trim(request("DefaultPicUrl"))
article_key=trim(request("key"))

set rs=server.createobject("adodb.recordset")
sql="select * from article"
rs.open sql,conn,1,3
rs.addnew
rs("article_class")=article_class
rs("article_title")=article_title
rs("article_content")=article_content
if IncludePic="yes"then
rs("article_pic_or")=1
if article_image<>"" then
rs("article_image")=article_image
end if
else rs("article_pic_or")=0
end if
rs("article_author")=article_author
rs.update
rs.close
set rs=nothing
Response.Write"<script language=JavaScript>"
Response.Write"alert(""恭喜!添加成功!欢迎继续添加!"");"
Response.Write"window.location='Add_article1.asp'"
Response.Write"</script>"

表单中的内容我看都没有错,主体内容我用的编辑器,应该没有错误,就是提示‘update’有错!
...全文
190 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
flybird99 2004-11-26
  • 打赏
  • 举报
回复
我知道了,你们也都没仔细帮我看看,呵呵,不要笑话我,<select name="artile_class">这句看出有什么错了吗?谢谢大家,一切OK了!
hushuang7094 2004-11-26
  • 打赏
  • 举报
回复
可以用 response.write trim(request("article_class"))\,response.write sql等来测试你上页传来的值,看是否是有值,是否为空等,然后注释掉,
pq16344 2004-11-26
  • 打赏
  • 举报
回复
估计是你的字段类型和你提交的数据类型是不同的
hushuang7094 2004-11-26
  • 打赏
  • 举报
回复
若是文本字段,则要检查数据库的该字段的设置:必填字段:否; 允许孔字符串:是;还有文本筐的字段大小也要设置好,若超出能存储的范围也会报错
若是数字类型的,则字段值必须有数字,而不能为空
tutuaction 2004-11-26
  • 打赏
  • 举报
回复
我给你一个调试的建议,对于数据库的操作,最好先最终的sql语句打印出来,利用数据库工具看看对不对?然后再注释掉,事半功倍
flybird99 2004-11-26
  • 打赏
  • 举报
回复
我晕了,我知道哪错了,是数据库内我把类别写入弄成必填值,而类别没写进去,我再看看为什么写不进去!
hushuang7094 2004-11-26
  • 打赏
  • 举报
回复
你的rs.open sql,conn,1,3表示当前数据记录可自由移动,但是只是可读的,就是说不可修改,估计是你的指针类型设错了
flybird99 2004-11-26
  • 打赏
  • 举报
回复
article_pic_or是数值,article_image是文本,刚才说错了!
flybird99 2004-11-26
  • 打赏
  • 举报
回复
文本,类型除了ID自动编号和article_image是数值、article_content是备注,其余都是文本,大小都绝对不会不够的
hushuang7094 2004-11-26
  • 打赏
  • 举报
回复
还有将rs.open sql,conn,1,3改成别的看看,我一般的是rs.open sql,conn,3,2
hushuang7094 2004-11-26
  • 打赏
  • 举报
回复
article_image是什么类型的数据?
flybird99 2004-11-26
  • 打赏
  • 举报
回复
Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'

[Microsoft][ODBC Microsoft Access Driver]行中有错误

/myweb/add_article1.asp,行 36


36行即为‘rs.update’这一行!
samyan 2004-11-26
  • 打赏
  • 举报
回复
报错得提示是什么?贴出来看看!
flybird99 2004-11-26
  • 打赏
  • 举报
回复
id字段自动编号没错,数据库的值设置都可以为空,不过写入程序中我除了article_image外,其余都要求添写不为空,就算article_image不加条件句,也不应该都写不进去吧,我给("article_pic_or")写值1或0是为了调用时候好用,当然不这样写也行,但这样写也不应该影响数据库写入吧?那是哪的问题呢?
yqh1314 2004-11-26
  • 打赏
  • 举报
回复
有那样的可能` 但是最大的可能是没有值或者是空值
samyan 2004-11-26
  • 打赏
  • 举报
回复
我觉得你不必要在添加得时候判断啊
if IncludePic="yes"then
a=1
else
a=IncludePic
end if

rs("article_pic_or")=a

还有,既然article_image可以为空,
if article_image<>"" then
rs("article_image")=article_image
end if
这一段是多余得
你完全可以直接rs("article_image")=article_image
tjficcbw 2004-11-26
  • 打赏
  • 举报
回复
以上要是每个都有值,有可能你的数据库ID字段不是自动生成的(在传库的时候丢失主键)
flybird99 2004-11-26
  • 打赏
  • 举报
回复
有啊,article_image可以为空,所以我加了个条件句,其它的都不能为空,我已经在表单提单时加了限制!
micher_yan 2004-11-26
  • 打赏
  • 举报
回复
rs("article_class")=article_class
rs("article_title")=article_title
rs("article_content")=article_content
if IncludePic="yes"then
rs("article_pic_or")=1
if article_image<>"" then
rs("article_image")=article_image
end if
else
rs("article_pic_or")=0
end if
rs("article_author")=article_author
这里面每个变量都有值吗?
flybird99 2004-11-26
  • 打赏
  • 举报
回复
如果看不出来,可以看看这是整个文件,就是长点,可以先看上面的写入代码,编辑器写入是另一个文件,这是没有问题的:
<%
select case Request("action")
case ""
article
case "save"
savearticle
end select
sub savearticle()
dim article_title,article_content,article_class,article_author,IncludePic,article_image,article_key
article_class=trim(request("article_class"))
article_title=trim(request("title"))
article_content=Server.HTMLEncode(request("content"))
IncludePic=trim(request("IncludePic"))
article_author=trim(request("author"))
article_image=trim(request("DefaultPicUrl"))
article_key=trim(request("key"))

set rs=server.createobject("adodb.recordset")
sql="select * from article"
rs.open sql,conn,1,3
'set rs=conn.execute("select * from article")
rs.addnew
rs("article_class")=article_class
rs("article_title")=article_title
rs("article_content")=article_content
if IncludePic="yes"then
rs("article_pic_or")=1
if article_image<>"" then
rs("article_image")=article_image
end if
else rs("article_pic_or")=0
end if
rs("article_author")=article_author
rs.update
rs.close
set rs=nothing
Response.Write"<script language=JavaScript>"
Response.Write"alert(""恭喜!添加成功!欢迎继续添加!"");"
Response.Write"window.location='Add_article1.asp'"
Response.Write"</script>"
'rs.close:set rs=nothing
end sub
sub article()
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {color: #FFFFFF}
.style2 {font-size: 9px}
.style3 {font-size: 10px}
.style4 {font-size: 10}
.style5 {font-size: 12px}
-->
</style>
<script language = "JavaScript">
function AddItem(strFileName){
document.myform.IncludePic.checked=true;
document.myform.DefaultPicUrl.value=strFileName;
document.myform.DefaultPicList.options[document.myform.DefaultPicList.length]=new Option(strFileName,strFileName);
document.myform.DefaultPicList.selectedIndex+=1;
}
function CheckForm()
{
if (editor.EditMode.checked==true)
document.myform.Content.value=editor.HtmlEdit.document.body.innerText;
else
document.myform.Content.value=editor.HtmlEdit.document.body.innerHTML;

if (document.myform.article_class.value=="")
{
alert("文章所属栏目不能为空!");
document.myform.article_class.focus();
return false;
}
if (document.myform.Title.value=="")
{
alert("文章标题不能为空!");
document.myform.Title.focus();
return false;
}
if (document.myform.Key.value=="")
{
alert("关键字不能为空!");
document.myform.Key.focus();
return false;
}
if (document.myform.author.value=="")
{
alert("文章来源不能为空!");
document.myform.author.focus();
return false;
}
if (document.myform.Content.value=="")
{
alert("文章内容不能为空!");
editor.HtmlEdit.focus();
return false;
}
if (document.myform.Content.value.length>65536)
{
alert("文章内容太长,超出了ACCESS数据库的限制(64K)!建议将文章分成几部分录入。");
editor.HtmlEdit.focus();
return false;
}
return true;
}
function loadForm()
{
editor.HtmlEdit.document.body.innerHTML=document.myform.Content.value;
return true
}
</script>
</head>

<body onLoad="javascipt:setTimeout('loadForm()',2000);">
<form method="POST" name="myform" onSubmit="return CheckForm();" action="?action=save" target="_self"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" colspan="3" bgcolor="#6699CC"><div align="center" class="style1">添加文章</div></td>
</tr>
<tr>
<td width="16%" height="20"><div align="right">所属栏目:</div></td>
<td colspan="2"><select name="artile_class">
<option selected>请选择</option>
<% set rs1=Server.CreateObject("adodb.recordset")
sql="select * from article_class"
rs1.open sql,conn,1,1
do while not rs1.eof%>
<option value="<%= rs1("classid") %>"><%= rs1("article_class") %></option>
<%rs1.movenext
loop
rs1.close
set rs1=nothing%>
</select></td>
</tr>
<tr>
<td height="20"><div align="right">文章标题:</div></td>
<td height="20" colspan="2"><input name="title" type="text" size="25" maxlength="200"></td>
</tr>
<tr>
<td height="20"><div align="right">关键字:</div></td>
<td height="20" colspan="2"><input name="key" type="text" size="25" maxlength="200" value="<%=session("Key")%>"></td>
</tr>
<tr>
<td height="20"><div align="right">来源:</div></td>
<td height="20" colspan="2"><input name="author" type="text" size="25" maxlength="200" value="<%=session("author")%>"></td>
</tr>
<tr>
<td height="188"><p align="right">文章内容:</p>
<p>
<span class="style2"><span class="style3"><span class="style4"><span class="style5"><font color="#006600">· 如果是从其它网站上复制内容,并且内容中包含有图片,本系统将会把图片复制到本站服务器上,系统会因复制图片的大小而影响速度,请稍候。<br>
· 换行请按Shift+Enter</font><br>
<font color="#006600">· 另起一段请按Enter</font><font color="#006600"></font></span></span></span></span></p></td>
<td height="188" colspan="2"><textarea name="Content" style="display:none"></textarea>
<iframe ID="editor" src="editor.asp" frameborder=1 scrolling=no width="600" height="405"></iframe></td>
</tr>
<tr>
<td height="20"><div align="right">包含图片:</div></td>
<td width="12%" height="20"><input name="IncludePic" type="checkbox" value="yes"></td>
<td width="72%">直接从上传图片中选择:
<select name="DefaultPicList" id="DefaultPicList" onChange="DefaultPicUrl.value=this.value;">
<option selected>不指定首页图片</option>
</select></td>
</tr>
<tr>
<td height="20"><div align="right">上传图片:</div></td>
<td height="20" colspan="2"><input name="DefaultPicUrl" type="text" id="DefaultPicUrl" size="45" maxlength="200"></td>
</tr>
<tr>
<td height="20" colspan="3"><div align="center">
<input name="Submit" type="submit" class="input-text" value="提 交">
 
<input name="Submit2" type="reset" class="input-text" value="重 写">
</div></td>
</tr>
</table>
</form>
</body>
</html>
<%end sub%>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧