i create a winform program and have a listbox and delete button in my form. my listbox is using a datasource/databinding that come from .mdb(Microsoft Access) file. here are the delete button code i use now
ignore about the message box, the code above successful delete the item from my listbox but not from the database(mdb), so this thing give me a problem because after reopen the form i notice the item that has been deleted before is still there(its just delete from listbox but not mdb)
i also has tried to change delete command from " + listBox1.SelectedItem + " to "selectedPCNo" but i don't get luck..does anyone know how to achieve this? sorry for my bad english anyway..
Code:
private void deletepcsetting_Click(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("Are you sure want to delete PC No " + listBox1.SelectedItem + "?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dialogResult == DialogResult.Yes)
{
PCNo selectedPCNo = (PCNo)listBox1.SelectedItem;
if (selectedPCNo != null)
{
OleDbCommand cmd = new OleDbCommand("DELETE FROM ClientListing WHERE PCNO = " + listBox1.SelectedItem + "", GetConnection());
_pcno.Remove(selectedPCNo);
}
GetConnection().Close();
}
}
i also has tried to change delete command from " + listBox1.SelectedItem + " to "selectedPCNo" but i don't get luck..does anyone know how to achieve this? sorry for my bad english anyway..