我執行UPDATE
或與WHERE
聲明INSERT
命令,我已經得到了這個錯誤:火鳥未知令牌哪裏
這裏是我的代碼:
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
try
{
FbConnection con = new FbConnection(@"User = SYSDBA; Password = masterkey; Database = D:\TDWORK.fdb; DataSource = localhost; Port = 3050; Dialect = 3; Charset = NONE; Role = admin; Connection lifetime = 15; Pooling = true; MinPoolSize = 0; MaxPoolSize = 50; Packet Size = 8192; ServerType = 0; ");
FbCommand cmd = new FbCommand("UPDATE OR INSERT INTO ZAPOSLENI (ULOGA) VALUES (" + dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() + ") WHERE ZAPID = " + dataGridView1.Rows[e.RowIndex].Cells[0].Value + " ", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
這裏是如何命令看起來像調試器在其中插入值時:
UPDATE OR INSERT INTO ZAPOSLENI (ULOGA) VALUES (1) WHERE ZAPID = 0
您當前的代碼是不安全的,因爲它是開放的SQL注入。你應該真的使用參數。 –
你是什麼意思 – Pacijent
你將值連接到查詢字符串中,這是不安全的。您需要使用參數,請參閱示例[此答案](http://stackoverflow.com/a/10438372/466862) –