Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# INSERT INTO语句错误中的语法错误_C#_Oledb - Fatal编程技术网

C# INSERT INTO语句错误中的语法错误

C# INSERT INTO语句错误中的语法错误,c#,oledb,C#,Oledb,我已通过“OLEDB”连接成功连接数据库。我使用了一个表作为注册表单,它工作得很好,然后我将另一个表与另一个表单一起使用,但是使用了相同的代码,有着所需的差异,但我一直遇到这个错误: INSERT INTO语句中出现语法错误 此部分代码的错误为: { string sqlpost2 = "insert into postqr(Professor,Title,Body)"; sqlpost2 += "value('" + postname + "','" + posttitle +

我已通过“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();
}

在您的SQL代码中,尝试在SQL关键字VALUES

前面加一个空格。使用
OleDbParameter
s。此外,我认为您想要的是
值(…)
而不是
值(…)
这对我不起作用
您应该发布该代码,以便获得急需的帮助。为此,请检查空格和拼写如何使用OLEDB参数?您可以在此处找到OLEDB参数使用示例