Friday, 8 August 2014

How to delete in C#

Cursor.Current = Cursors.WaitCursor;
            try
            {
                if (cbxBillNo.Text != "Select")
                {
                    if (MessageBox.Show("Are you Sure to Delete?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        string strBill = "Delete * from T_DeliNoteInv Where IDs='" + cbxBillNo.Text + "'";
                        string strBillInfo = "Delete * from T_DeliDetails Where IDs='" + cbxBillNo.Text + "'";
                        con = new OleDbConnection(dbCon());
                        OleDbCommand cmdBill = new OleDbCommand(strBill, con);
                        OleDbCommand cmdBillInfo = new OleDbCommand(strBillInfo, con);
                        con.Open();
                        cmdBill.ExecuteNonQuery();
                        cmdBillInfo.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("Deleted Bill No:" + cbxBillNo.Text, "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        cbxBillNo.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Select Bill No", "Select", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbxBillNo.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            Cursor.Current = Cursors.Default;

No comments:

Post a Comment