Insert into 语句语法错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Insert into 语句语法错误相关的知识,希望对你有一定的参考价值。

Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] INSERT INTO 语句的语法错误。
代码:
<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined")

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2)
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined")
formVal = emptyVal;
else
if (altVal != "")
formVal = altVal;
else if (delim == "'") // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
else
formVal = delim + formVal + delim;


MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "") + formVal;

MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

if (!MM_abortEdit)
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl)
Response.Redirect(MM_editRedirectUrl);




%>
<%
var RecordsetCDB = Server.CreateObject("ADODB.Recordset");
RecordsetCDB.ActiveConnection = MM_ConnCDB_STRING;
RecordsetCDB.Source = "SELECT * FROM [Database]";
RecordsetCDB.CursorType = 0;
RecordsetCDB.CursorLocation = 2;
RecordsetCDB.LockType = 1;
RecordsetCDB.Open();
var RecordsetCDB_numRows = 0;
%>
谢谢大家了!!!

<%
// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined")

// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2)
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined")
formVal = emptyVal;
else
if (altVal != "")
formVal = altVal;
else if (delim == "'") // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
else
formVal = delim + formVal + delim;


MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "") + formVal;

MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

if (!MM_abortEdit)
// execute the insert
var MM_editCmd = Server.CreateObject('ADODB.Command');
MM_editCmd.ActiveConnection = MM_editConnection;
MM_editCmd.CommandText = MM_editQuery;
response.write MM_editQuery
response.end()
MM_editCmd.Execute();
MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl)
Response.Redirect(MM_editRedirectUrl);




%>
<%
var RecordsetCDB = Server.CreateObject("ADODB.Recordset");
RecordsetCDB.ActiveConnection = MM_ConnCDB_STRING;
RecordsetCDB.Source = "SELECT * FROM [Database]";
RecordsetCDB.CursorType = 0;
RecordsetCDB.CursorLocation = 2;
RecordsetCDB.LockType = 1;
RecordsetCDB.Open();
var RecordsetCDB_numRows = 0;
%>

把这个页面的执行结果贴出来。
参考技术A MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values ('" + MM_dbValues + "')";
好好看看书或文档,注意列的数据类型,字符型要加'号

向access数据库插入出现“insert into 语法错误”

OleDbConnection MyConn;
protected DBHelp ds1 = new DBHelp();
protected void Button1_Click(object sender, EventArgs e)

if (Page.IsValid)

try

ds1.DBopen();

string title = (string)TextBox1.Text.Trim();
string content = (string)TextBox2.Text.Trim();
DateTime time = DateTime.Now;
//对文件进行重命名,将系统时间做为文件名
String time1 = DateTime.Now.ToString("yyyyMMddhhmmss");
//传小图
String fileName = File1.FileName;
String fileType = fileName.Substring(fileName.LastIndexOf('.'));

//获取上传文件夹
String directory = Server.MapPath("~/image/");
//上传
File1.SaveAs(directory + "JY" + time1 + fileType);
if (fileType != ".jpg" && fileType != ".JPG" && fileType != ".gif" && fileType != "GIF" && fileType != ".bmp" && fileType != ".BMP")

Page.ClientScript.RegisterStartupScript(GetType(), "", "alert('您必须选择一个jpg/gif/bmp文件!");
return;

//上传
File1.SaveAs(directory + "JY" + time1 + fileType);

string StrSql = "Insert Into tb_product(title,content,image,addtime) VALUES('" + title + "','" + content + "','" + "image/" + "RT" + time + fileType + "','" + time + "')";

int i = ds1.ExecuteSql(StrSql);
if (i > 0)

Response.Write("<script> alert(\"添加成功!\")</script>");

else

Response.Write("<script> alert(\"添加失败!\")</script>");

this.TextBox1.Text = "";
this.TextBox2.Text = "";


catch (Exception ex)

Response.Write("<script>alert('" + ex.Message + "')</script>");

finally


ds1.DBclose();




我试过把这个语句放到sql2005可以执行的,但是用到access就出现如题的错误。请高手指点。

哥么,可以自己多试试,实在不行看看这个:
sql="insert into tb_product(title) values('" & title & "')"
参考技术A mssql语法与access中的sql语法有点不一样的

以上是关于Insert into 语句语法错误的主要内容,如果未能解决你的问题,请参考以下文章

INSERT INTO 语句的语法错误。

INSERT INTO 语句的语法错误

INSERT INTO 语句的语法错误。

insert into 语法错误

insert into语句的语法错误

执行 INSERT INTO 语句时出现语法错误