-5

I'm trying to write a form update a selected row in sqlite in win forms applications C#. But there is still an error:

SQL logic error
near "ID": syntax error

My part of code:

private void button4_Click(object sender, EventArgs e)
        {
            string Transport = "Update TransportMed set Imię = "+textBox2.Text+", Nazwisko = " +textBox3.Text+", PESEL ="+textBox3.Text+"where ID = " + dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            ExcecuteQuery(Transport);
            LoadData();
        }
Maria
  • 117
  • 9

1 Answers1

1

As @jdweng has mentioned, you need a space before where:

string Transport = "Update TransportMed set Imię = " + textBox2.Text + ", Nazwisko = " + textBox3.Text + ", PESEL =" + textBox3.Text + " where ID = " + dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

Please be careful that the current method is vulnerable to SQL Injection attacks. You have to use Sql parameters to avoid it. Read more here: What are good ways to prevent SQL injection?

Muhammad Azeez
  • 926
  • 8
  • 18