我有一个通过“ OLEDB”连接成功连接的数据库。我已经将一个表格用于注册表单,并且工作正常,然后又将另一个表格与另一表格一起使用,但是具有相同的代码,但有必要的区别,但我不断收到此错误:
INSERT INTO语句中的语法错误。
此代码部分的错误:
{
string sqlpost2 = "insert into postqr(Professor,Title,Body)";
sqlpost2 += "value('" + postname + "','" + posttitle + "','" + postbody + "')";
DBFunction.ChangeTable(sqlpost2, "DBS.accdb");
}
这是该页面中使用的所有代码:
protected void Button9_Click(object sender, EventArgs e)
{
string postname = this.Postuser.Text;
string postpass = this.Postpass.Text;
string posttitle = this.TOP.Text;
string postbody = this.BOP.Text;
string sqlstr2 = "select * from professors WHERE pname='" + postname + "' AND ppass='" + postpass + "'";
DataTable dt1 = DBFunction.SelectFromTable(sqlstr2, "DBS.accdb");
if (dt1.Rows.Count > 0)
{
string sqlpost2 = "insert into postqr(Professor,Title,Body)";
sqlpost2 += "values('" + postname + "','" + posttitle + "','" + postbody + "')";
DBFunction.ChangeTable(sqlpost2, "DBS.accdb");
}
else
this.Label1.Text = "Posting on this wall is only allowed for professors and it seems that you're not one";
DataList1.DataBind();
}
答案 0 :(得分:0)
在您的SQL代码中尝试在SQL关键字 VALUES
之前放置一个空格