0

I have a database connected successfully by "OLEDB" connection. I've used one table for the sign up form and it worked perfectly and then I used the other table with another form, but with the same code, with the differences that are needed, yet I keep getting this error:

Syntax error in INSERT INTO statement.

The error is for this part of the code:

{
    string sqlpost2 = "insert into postqr(Professor,Title,Body)";
    sqlpost2 += "value('" + postname + "','" + posttitle + "','" + postbody + "')";
    DBFunction.ChangeTable(sqlpost2, "DBS.accdb");
}

This is all of the code used in that page:

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();
}
5
  • 4
    Use OleDbParameters. Commented Apr 6, 2019 at 19:47
  • 3
    Also, i think you want values(...) not value(...) Commented Apr 6, 2019 at 19:48
  • it doesn't work for me you should post that code so you can get the help you badly need. For this, check the spaces and spelling Commented Apr 6, 2019 at 19:48
  • How can I use oledbparameters? Commented Apr 6, 2019 at 19:50
  • 1
    You can find an example of OleDbParameter use here learn.microsoft.com/en-us/dotnet/api/… Commented Apr 6, 2019 at 19:56

1 Answer 1

1

in your SQL code try to put a space before the SQL Keyword VALUES

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.