我试图在上传图片后将记录插入到访问数据库中。图像保存正确但我无法使插入命令起作用。
set o = new clsUpload
if o.Exists("cmdSubmit") then
'get client file name without path
sFileSplit = split(o.FileNameOf("txtFile"), "\")
sFile = sFileSplit(Ubound(sFileSplit))
o.FileInputName = "txtFile"
o.FileFullPath = Server.MapPath("ads") & "\" & sFile
o.save
if o.Error = "" then
response.write "Success. File saved to " & o.FileFullPath & ". County = " & o.ValueOf("County")
Company = o.ValueOf("Company")
County = o.ValueOf("County")
imgfile = sFile
Set OBJdbConnection = Server.CreateObject("ADODB.Connection")
OBJdbConnection.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=C:\Users\User\Desktop\Websites\123justlistit\wwwroot\admin\123justlistit.mdb"
Set sqlIns = Server.CreateObject("ADODB.Command")
sqlIns.ActiveConnection = OBJdbConnection
sqlIns.commandtext="insert into ads (company, county, image)values(?,?,?)"
sqlIns.Parameters.Append sqlIns.CreateParameter("@company", adVarChar, adParamInput, 25, Company)
sqlIns.Parameters.Append sqlIns.CreateParameter("@county", adVarChar, adParamInput, 25, County)
sqlIns.Parameters.Append sqlIns.CreateParameter("@imgfile", adVarChar, adParamInput, 50, imgfile)
sqlIns.execute
OBJdbConnection.Close
else
response.write "Failed due to the following error: " & o.Error
end if
end if
set o = nothing
我得到了:
Microsoft JET Database Engine error '80040e14'
Syntax error in INSERT INTO statement.
我认为它与尝试插入图像的文件名有关,但我不确定
答案 0 :(得分:0)
您的两个参数名称(@company
和@county
)与列名称冲突。将参数名称更改为不同的名称,或者(更好地)将查询字符串中的标识符放在方括号中:
sqlIns.CommandText = "INSERT INTO [ads] ([company], [county], [image]) VALUES (?,?,?)"
使用方括号还可以避免标识符包含空格或与保留字冲突的问题。