-1

I want to insert email in Table with only one column. I tried on 2 way. First time I tried with commandText and second time I tried with parapeters. But the both solution give me the same error.

System.Data.OleDb.OleDbException: 'Syntax error in INSERT INTO statement.'

I don't see any error in INSERT STATEMENT. Maybe the problem is in TABLE?

 using (OleDbCommand cmd = new OleDbCommand())
 {
    cmd.Connection = conn;
    cmd.CommandText = "SELECT COUNT (email) FROM [User] WHERE [email] LIKE '" + userEmail + "';";
    conn.Open();
    int count = Convert.ToInt32(cmd.ExecuteScalar()); // This passed
    if (count == 0)
    {
        string query = @"INSERT INTO User (email) VALUES (@email)";
        string cmdText= @"INSERT INTO User (email) VALUES ('"+userEmail+"')";
        OleDbCommand command = new OleDbCommand(cmdText, conn);
   //     command.Parameters.AddWithValue("@email", "userEmail");
       // command.CommandText = query;
        command.ExecuteNonQuery(); // I GOT ERROR HERE
    }
    conn.Close();
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
MiOnIs
  • 125
  • 12

2 Answers2

3

User is a keyword. You should INSERT INTO [USER] instead

hardkoded
  • 18,915
  • 3
  • 52
  • 64
0
string cmdText= @"INSERT INTO User (email)) VALUES ('"+userEmail+"')";

you have one ')' too many after (email)