WORK 16 ลบข้อมูล (DELETE DATA)
Code : FormBooks.cs
ButtonDeleteClick :
{
String dbName = "kvcLib.ldb";
String dataSource = "data source= " + dbName;
SQLiteConnection con = new SQLiteConnection(dataSource);
SQLiteCommand com = new SQLiteCommand(dataSource, con);
String qry = "DELETE FROM books " +
"WHERE ID = " + this.textBoxID.Text + ";";
con.Open();
com.CommandText = qry;
try {
com.ExecuteNonQuery();
MessageBox.Show("ลบข้อมูลสำเร็จ");
} catch (Exception ex) {
MessageBox.Show("มีความผิดพลาด ลบข้อมูลไม่สำเร็จ\n" + ex.ToString());
}
con.Close();
}
String dataSource = "data source= " + dbName;
SQLiteConnection con = new SQLiteConnection(dataSource);
SQLiteCommand com = new SQLiteCommand(dataSource, con);
String qry = "DELETE FROM books " +
"WHERE ID = " + this.textBoxID.Text + ";";
con.Open();
com.CommandText = qry;
try {
com.ExecuteNonQuery();
MessageBox.Show("ลบข้อมูลสำเร็จ");
} catch (Exception ex) {
MessageBox.Show("มีความผิดพลาด ลบข้อมูลไม่สำเร็จ\n" + ex.ToString());
}
con.Close();
}
0 ความคิดเห็น