Guest User

Guest User

  • Tech Writer
  • 529
  • 41.2k

C# Delete Query I Wan just ADD 2 Line Yes,NO

Jun 18 2021 7:49 AM
if (string.IsNullOrWhiteSpace(Regno.Text))
{
    MessageBox.Show("Id Field Is Empty First Click On Datagrid Cell To populate it with a value");
}           
else
{
    string deleteSQLQuery = "DELETE FROM tbl_member WHERE RegNo=@regno";
    SqlCommand deleteCommand;           
    try
    {               
        //Open Database Connection
        connection.OpenDBConnection();
        deleteCommand = new SqlCommand(deleteSQLQuery, connection.getDatabaseConnection());
        deleteCommand.Parameters.Add("@regno", SqlDbType.Int).Value = int.Parse(Regno.Text);           
        //Check If The Data has been deleted
        if (deleteCommand.ExecuteNonQuery() == 1)
        {                
            //MessageBox.Show("Data Deleted Successfully..... ");           
        }
    }
    catch (Exception err)
    {
        MessageBox.Show("Err " + err);
    }
    finally
    {
        //close Database Connection
        connection.CloseDBConnection();
    }
    //clear input fields after Deleting data from mysql database
    clearFields();
    //Refresh datagridview after deleting data from database
    refreshDatagridView("");
}

ADD THIS line

(MessageBox.Show("Do You Need To Delete Data Of Member Register :- " + Regno.Text.ToString() + "", "Member Register", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
MessageBox.Show("Row Not Remove", "Remove Row", MessageBoxButtons.OK, MessageBoxIcon.Information);

 


Answers (4)