为什么不能向数据库中添加数据?

marf_cn 2002-05-31 10:35:12
做一个新闻发布系统,添加页面不能向数据库中加数据,请大家帮我看一下。
access数据库
表:tbl_news

字段及数据类型:
ID 自动编号
title 文本
content 备注
sourcefile 文本 (出处)
reship 文本 (转载)
/----------------------------
addnews.asp (纯html文件)
<HTML>
<HEAD>
<TITLE> 新闻添加</TITLE>
</HEAD>
<BODY>
<CENTER>
<p><FONT SIZE=3 COLOR="blue"><B>添加新闻</B></FONT></p>
<hr>
<p>
<form method=POST action="addresult.asp">
<table>
<tr>
<td align=right>新闻标题</td>
<td>
<input type="text" name="txttitle" size="72">
</td>
</tr>
<tr>
<td align=right>新闻内容</td>
<td>
<textarea name="txtcnt" rows="15" cols="70"></textarea>
</td>
</tr>
<tr>
<td align=right>出处</td>
<td>
<input type="text" name="txtsf">
</td>
</tr>
<tr>
<td align=right>转载</td>
<td>
<input type="text" name="txtrsh">
</td>
</tr>
<tr>
<td align=right>
<input type="submit" value="添加新闻" name="submit">
</td>
<td>
<input type="reset" name="reset">
</td>
</tr>
</table>
</form>
</CENTER></BODY>
</HTML>
/----------------------------------------------
添加结果页面addresult.asp :

<!--#include file="cndb.asp"-->
<%
data=" '"&request("txttitle")&"','"&request("txtcnt")&_
"','"&request("txtsf")&"','"&request("txtrsh")&_
"','"&now&"' "
set rs=server.createobject("adodb.recordset")
sql="insert into tbl_news(title,content,sourcefile,reship,time) values("&data&")"
cn.execute(sql)
%>
<html>
<head>
<title>添加成功</title>
</head>
<body>
添加成功!
<a href="addnews.asp">返回</a>
</body>
</html>
<%rs.close
cn.close
%>
/----------------------
cndb.asp的代码:(这个文件是没问题的,用在删除页面中是好的)
DbPath = SERVER.MapPath("WebCenter.mdb")
Set cn = Server.CreateObject("ADODB.Connection")
cn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DbPath
/-----------------------------------------------------------------
IE说insert into语句有问题,又说"cn.execute(sql)" 这句有问题,我觉得没有,大家帮忙看一下。
...全文
138 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhenhao 2002-05-31
  • 打赏
  • 举报
回复
语句有问题,不全。
wangfei2428 2002-05-31
  • 打赏
  • 举报
回复
sql="insert into tbl_news(title,content,sourcefile,reship,time) values("&data&")"

sql语句不规范
sql="insert into tbl_news(title,content,sourcefile,reship,time) values ('"&title&"','"&content&"','"&sourcefile&"','"&reship&"','"&time&"')"
gshope 2002-05-31
  • 打赏
  • 举报
回复
把NOW改成NOW(),绝对不是getdate()
playmud 2002-05-31
  • 打赏
  • 举报
回复
now
改成now()
或者getdate()
silentlamb 2002-05-31
  • 打赏
  • 举报
回复
看看时间格式对不对?
gzj0815 2002-05-31
  • 打赏
  • 举报
回复
cn.execute(sql)这条语句不行的,
如果要查看可以,update or delete 不行!
可以用
cn.open data,cn,3,3试一下
silentlamb 2002-05-31
  • 打赏
  • 举报
回复
insert into 字段列表 values 值列表
两个列表必须是一一对应的
phoenixlj 2002-05-31
  • 打赏
  • 举报
回复
权限问题,在ntfs格式中,如果使用Access数据库,必须把属性设置为everyone都可以写,这样就可以写进去了。
lanying 2002-05-31
  • 打赏
  • 举报
回复
你先Response.Write sql看看

28,391

社区成员

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

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