C# INSERT INTO语句错误中的语法错误
我已通过“OLEDB”连接成功连接数据库。我使用了一个表作为注册表单,它工作得很好,然后我将另一个表与另一个表单一起使用,但是使用了相同的代码,有着所需的差异,但我一直遇到这个错误: INSERT INTO语句中出现语法错误 此部分代码的错误为:C# INSERT INTO语句错误中的语法错误,c#,oledb,C#,Oledb,我已通过“OLEDB”连接成功连接数据库。我使用了一个表作为注册表单,它工作得很好,然后我将另一个表与另一个表单一起使用,但是使用了相同的代码,有着所需的差异,但我一直遇到这个错误: INSERT INTO语句中出现语法错误 此部分代码的错误为: { string sqlpost2 = "insert into postqr(Professor,Title,Body)"; sqlpost2 += "value('" + postname + "','" + posttitle +
{
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();
}
在您的SQL代码中,尝试在SQL关键字VALUES前面加一个空格。使用
OleDbParameter
s。此外,我认为您想要的是值(…)
而不是值(…)
这对我不起作用
您应该发布该代码,以便获得急需的帮助。为此,请检查空格和拼写如何使用OLEDB参数?您可以在此处找到OLEDB参数使用示例