Share via

Missing operator in SQL

Anonymous
2018-04-25T13:12:23+00:00

Hello

When I compile my this part of my code the Microsoft visual studio give Eror : (System.Data.OleDb.OleDbException: 'Syntax error (missing operator) in query expression 'people where Id=1'.')

This is my code:

private void button3_Click(object sender, EventArgs e)

        {

            cmd.CommandText = "Delete people where Id=" + int.Parse(textBox5.Text) + ",Name='" + textBox1.Text + "',Last_name='" + textBox2.Text + "',Data='" + textBox2.Text + "', Code_Ozviat=" + int.Parse(textBox4.Text);

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();

            cmd.CommandText = "select * from people";

            cmd.CommandType = CommandType.Text;

            cmd.ExecuteNonQuery();

            DataTable tb = new DataTable();

            OleDbDataAdapter dap = new OleDbDataAdapter(cmd);

            dap.Fill(tb);

            dataGridView1.DataSource = tb;

            }

what can I do for resolve this eror?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2018-04-25T17:15:13+00:00

    Your SQL statement has several errors.  Try this:

    cmd.CommandText = "Delete FROM people where Id=" + int.Parse(textBox5.Text) + " AND Name='" + textBox1.Text + "' AND Last_name='" + textBox2.Text + "' AND Data='" + textBox2.Text + "' AND Code_Ozviat="

    • int.Parse(textBox4.Text);

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2018-04-25T13:18:08+00:00

    For Access the syntax is: "delete * from ..."

    https://msdn.microsoft.com/en-us/library/bb177896(v=office.12).aspx

    Was this answer helpful?

    0 comments No comments