private void Delete ( )
{
try
{
if (TxtEmpcode.Text == "")
{
MessageBox.Show( "Please Enter the valid Employee Code", "CURD", MessageBoxButtons.OK, MessageBoxIcon.Information );
TxtEmpcode.Focus ( );
TxtEmpcode.Text = "";
TxtEmpName.Text = "";
TxtQual.Text = "";
TxtCom.Text = "";
TxtAdd.Text = "";
}
else
{
objconnection = new SqlConnection ( WebConfigurationManager.ConnectionStrings["Conn"].ConnectionString );
SqlCommand objcommand = new SqlCommand ( );
objcommand.Connection = objconnection;
objcommand.CommandType = CommandType.Text;
objcommand.CommandText = "Select Count(*) from Employee where EmpCode=" + TxtEmpcode.Text.Trim ( ) + "";
objconnection.Open ( );
int val = int.Parse ( objcommand.ExecuteScalar ( ).ToString ( ) );
if (val > 0)
{
objconnection = new SqlConnection ( WebConfigurationManager.ConnectionStrings["Conn"].ConnectionString );
objcommand = new SqlCommand ( );
objcommand.Connection = objconnection;
objcommand.CommandType = CommandType.Text;
objcommand.CommandText = "Delete from Employee where EmpCode=" + TxtEmpcode.Text.Trim ( ) + "";
objconnection.Open ( );
objcommand.ExecuteNonQuery ( );
objconnection.Close ( );
MessageBox.Show ( " Employee record is successfully Deleted", "CURD", MessageBoxButtons.OK, MessageBoxIcon.Information );
TxtEmpcode.Focus ( );
TxtEmpcode.Text = "";
TxtEmpName.Text = "";
TxtQual.Text = "";
TxtCom.Text = "";
TxtAdd.Text = "";
}
else
{
MessageBox.Show ( "Please Enter the valid Employee Code", "CURD", MessageBoxButtons.OK, MessageBoxIcon.Information );
MessageBox.Show ( "Employee record is successfully deleted" + TxtEmpcode.Text, "CURD", MessageBoxButtons.OK, MessageBoxIcon.Information );
TxtEmpcode.Focus ( );
TxtEmpcode.Text = "";
TxtEmpName.Text = "";
TxtQual.Text = "";
TxtCom.Text = "";
TxtAdd.Text = "";
}
}
}
catch (Exception ex)
{
MessageBox.Show ( "error occur", "CURD", MessageBoxButtons.OK, MessageBoxIcon.Error );
}
finally
{
objconnection.Close();
}
}