重大变更 文号:access数据库问题 加急!!!

来源:百度文库 编辑:中科新闻网 时间:2024/05/08 01:02:32
小弟正在做毕业设计,现在遇到一个非常棘手的问题,不知道怎么解决,希望大哥大姐帮帮忙!!我做的是一个新闻删除页面
问题:错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'y_id =' 中。
/manager/ynews/news_del_ok.asp, 第 16 行
代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../../Connections/data.asp" -->
<%

if(Request("y_id") <> "") then Command1__data_id = Request("y_id")

%>
<%

set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = MM_data_STRING
Command1.CommandText = "DELETE FROM ynews WHERE y_id =" + Replace(Command1__data_id, "'", "''") + " "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-size: xx-large;
font-weight: bold;
color: #FF0000;
}
.style2 {color: #FF0000; font-weight: bold;}
-->
</style>
</head>
<body>

<p> </p>
<p> </p>
<p> </p>
<p align="center" class="style1">删除成功!</p>
<p align="center" class="style2"> </p>
<p align="center" class="style2"><a href="news_edit.asp">继续</a>      <a href="news_list.asp">退出</a></p>
</body>
</html>
我的数据库id是长整型的,应该不用加'',我在一开始做这个页面时,数据库表中有一条记录,当时还能用,运行时我就给删除了,但是删完之后我又添加了记录,就不行了 .还有,我做更新页面时也出现这个问题 ,我都弄了好几天了,都是出现这个问题

你看看数据库中的id是以什么格式保存的如果是文本
id='值',也就是这样select * from [表] where id='值'
如果id是数字那么不用加引号:id=值,
select * from [表] where id=值
就可以了

那个replace函数是防止什么的?y_id接受的是字符串吗?字符串要加上引号的。

如果y_id不是数字类型的,那么需要加上'

Command1.CommandText = "DELETE FROM ynews WHERE y_id ='" + Replace(Command1__data_id, "'", "''") + "'"

我为你着急,我也想知道这问题的答案,因为我也遇到过!