INSERT INTO 语句的语法错误。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了INSERT INTO 语句的语法错误。相关的知识,希望对你有一定的参考价值。
<%
set conn=server.createobject("adodb.connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("db1.mdb")
id=request.Form("id")
name=request.Form("name")
dept=request.Form("dept")
position=request.Form("position")
data=request.Form("data")
exec="insert into hr(id,name,dept,position,data)values('"+id+"','"+name+"','"+dept+"','"+position+"','"+data+"')"
conn.execute exec
conn.close
set conn=nothing
%>
<%="恭喜!数据添加成功!"%>
提示:
技术信息(用于支持人员)
错误类型:
Microsoft JET Database Engine (0x80040E14)
INSERT INTO 语句的语法错误。
/bff/add.asp, 第 20 行
浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
网页:
POST 51 ??? /bff/add.asp
POST Data:
id=&name=&dept=&position=&data=&submit=%CC%E1%BD%BB
时间:
2009年4月9日, 11:50:06
看你的语句,一般来说,Access数据库的ID都是自动编号的,无法用INSERT语句插入。修改一下
exec="insert into hr(name,dept,position,data)values('"+name+"','"+dept+"','"+position+"','"+data+"')"
另外注意一下,ACCESS的数值型、布尔型不需要单引号 参考技术B exec="insert into hr(id,name,dept,position,data)values('"+id+"','"+name+"','"+dept+"','"+position+"','"+data+"')"
改成
exec="insert into hr([id],[name],[dept],[position],[data])values('"+id+"','"+name+"','"+dept+"','"+position+"','"+data+"')"
可以肯定的是name是access的保留字.所以要加[].为了百分之百的准确,所有的字段名都加上[]本回答被提问者采纳 参考技术C 把 exec 打印到网页上,把语句放到数据库中看看能否执行通过。
F# OleDb 语法错误在 INSERT INTO 语句中将数据从访问中提取到链接的 SQL Server
【中文标题】F# OleDb 语法错误在 INSERT INTO 语句中将数据从访问中提取到链接的 SQL Server【英文标题】:F# OleDb Syntax Error in INSERT INTO Statement Pulling Data from Access to Linked SQL Server 【发布时间】:2013-03-26 19:21:11 【问题描述】:我正在运行 F# 应用程序以将数据从 Access 表中提取到链接的 SQL Server 表中。以下是查询结果:
INSERT INTO dbo_TempTerm (UnitID, PolicyTermYear, InsuredName, PolicyNumber, RenewalDate, CovATotal, CovBTotal, CovLTotal, DwellExtn, AllOtherPerilDeductible, MedPay, TotalPremium, HurricaneDeductible, Zone, Subzone, PercentCRC, PercentCRD, YearBuilt, RenYrs, PercentCFD, PercentHA, PercentMLD, GRP1, PercentNH, QCLM, RateV, CRI, AgentCode, AgentName, AFOCode, PolicyType, PolicyForm, OC, DateCreated)
SELECT [UNIT ID], [POLICY TERM YEAR], [INSURED NAME], [POLICY #], [RENEWAL DT], [COV A TOTAL], [COV B TOTAL], [COV L TOTAL], [DWELL EXTN], [ALL/OTHER PERIL DEDUCTIBLE], [MED PAY], [TOT PREMIUM], [HURR DED], ZONE, SUBZONE, [%CRC], [%CRD], [YR BLT], RENYRS, [%CFD], [%HA], [%MLD], GRP1, [%NH], QCLM, [RATE V], CRI, [AGENT CODE], [AGENT NAME], [AFO CODE], [POLICY TYPE], [POLICY FORM], OC, DateCreated
FROM tblPrior
查询在 Access 中解析并运行良好。但在我的应用程序中,它引发了一个错误:INSERT INTO 语句中的语法错误。
这是我的 F#,虽然我认为它无关紧要。
module Data
open System.Data
open System.Data.OleDb
type Period = Prior | Current
let Upload (p:Period) db =
use conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + db + ";Persist Security Info=False;")
let execNonQuery s =
let comm = new OleDbCommand(s, conn) in
comm.ExecuteNonQuery() |> ignore
let (table,proc) = match p with
| Prior -> ("tblPrior" ,"InitPriorTable")
| Current -> ("tblCurrent","InitCurrentTable")
do conn.Open()
let u = sprintf "INSERT INTO dbo_TempTerm (UnitID, PolicyTermYear, InsuredName, PolicyNumber, RenewalDate, CovATotal, CovBTotal, CovLTotal, DwellExtn, AllOtherPerilDeductible, MedPay, TotalPremium, HurricaneDeductible, Zone, Subzone, PercentCRC, PercentCRD, YearBuilt, RenYrs, PercentCFD, PercentHA, PercentMLD, GRP1, PercentNH, QCLM, RateV, CRI, AgentCode, AgentName, AFOCode, PolicyType, PolicyForm, OC, DateCreated) SELECT [UNIT ID], [POLICY TERM YEAR], [INSURED NAME], [POLICY #], [RENEWAL DT], [COV A TOTAL], [COV B TOTAL], [COV L TOTAL], [DWELL EXTN], [ALL/OTHER PERIL DEDUCTIBLE], [MED PAY], [TOT PREMIUM], [HURR DED], ZONE, SUBZONE, [%%CRC], [%%CRD], [YR BLT], RENYRS, [%%CFD], [%%HA], [%%MLD], GRP1, [%%NH], QCLM, [RATE V], CRI, [AGENT CODE], [AGENT NAME], [AFO CODE], [POLICY TYPE], [POLICY FORM], OC, DateCreated FROM %s" table
// DEBUG.
printfn "%s" u
// DEBUG.
execNonQuery u
execNonQuery proc
【问题讨论】:
您是否尝试使用查询从访问中提取数据并直接插入到 SQl 服务器中? 【参考方案1】:Zone
和 DateCreated
都是 reserved words。很难预测保留字何时会给 SQL 语句带来麻烦,但在我看来,OleDb 可能不太宽容,即保留字更有可能失败。看看是否将所有出现的这些名称括起来将使INSERT
成功。
let u = sprintf "INSERT INTO dbo_TempTerm (UnitID, PolicyTermYear, InsuredName, PolicyNumber, RenewalDate, CovATotal, CovBTotal, CovLTotal, DwellExtn, AllOtherPerilDeductible, MedPay, TotalPremium, HurricaneDeductible, [Zone], Subzone, PercentCRC, PercentCRD, YearBuilt, RenYrs, PercentCFD, PercentHA, PercentMLD, GRP1, PercentNH, QCLM, RateV, CRI, AgentCode, AgentName, AFOCode, PolicyType, PolicyForm, OC, [DateCreated]) SELECT [UNIT ID], [POLICY TERM YEAR], [INSURED NAME], [POLICY #], [RENEWAL DT], [COV A TOTAL], [COV B TOTAL], [COV L TOTAL], [DWELL EXTN], [ALL/OTHER PERIL DEDUCTIBLE], [MED PAY], [TOT PREMIUM], [HURR DED], [ZONE], SUBZONE, [%%CRC], [%%CRD], [YR BLT], RENYRS, [%%CFD], [%%HA], [%%MLD], GRP1, [%%NH], QCLM, [RATE V], CRI, [AGENT CODE], [AGENT NAME], [AFO CODE], [POLICY TYPE], [POLICY FORM], OC, [DateCreated] FROM %s" table
【讨论】:
就是这样!太感谢了。下次看到类似这样的无意义错误时,我会检查保留字列表。 不客气,杰夫。在我链接的页面顶部附近,有一个 Database Issue Checker Utility 的链接。您可以下载该实用程序并使用它来检查您的 Access 数据库。它会警告您有关问题对象名称以及其他可能造成麻烦的问题。以上是关于INSERT INTO 语句的语法错误。的主要内容,如果未能解决你的问题,请参考以下文章