我想把用戶輸入作爲參數從我的firebird數據庫中刪除某些記錄。sql,簡單查詢從db中刪除記錄
所以我下面的代碼
private void btnOk_Click(object sender, EventArgs e)
{
string code = txtDeleteField.Text;
string connString = ConfigurationManager.AppSettings["DemoAppConnectionString"];
using (FbConnection conn = new FbConnection(connString))
{
using (FbCommand cmd = new FbCommand())
{
cmd.CommandText = "DELETE * FROM DEMOAPP WHERE CODE= @P1";
cmd.Parameters.AddWithValue("@P1", code);
cmd.Connection = conn;
conn.Open();
cmd.Transaction = conn.BeginTransaction();
int a = cmd.ExecuteNonQuery();
if (a == 0)
{
MessageBox.Show("Error!");
}
else
{
MessageBox.Show("Record deleted, ok!");
}
}
}
}
這段代碼產生錯誤
An unhandled exception of type 'FirebirdSql.Data.FirebirdClient.FbException' occurred in FirebirdSql.Data.FirebirdClient.dll Additional information: Dynamic SQL Error SQL error code = -104 Token unknown - line 1, column 8 *
如何使用'SELECT'刪除? – manji
這是你的實際碼嗎? 'SELECT'不會刪除記錄,這個錯誤似乎表明你嘗試做'DELETE * FROM',這是無效的(你應該把'*'留出。 –
typo :)這是刪除,現在它已更新 – panjo