indradeo kumar

indradeo kumar

  • 1.2k
  • 546
  • 7.6k

how to make update function using asp c#

Jul 23 2019 4:06 AM
Dear sir,
kindly help me to solve this.
 
protected void grvEmployee_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
CreateConnection();
OpenConnection();
Label id = (Label)grvEmployee.Rows[e.RowIndex].FindControl("lblEmplooyeId");
_sqlCommand.CommandText = "Sp_GridCrud2";
_sqlCommand.Parameters.AddWithValue("@Event", "Delete");
_sqlCommand.Parameters.AddWithValue("@EmplooyeId", Convert.ToInt32(id.Text));
_sqlCommand.CommandType = CommandType.StoredProcedure;
int result = Convert.ToInt32(_sqlCommand.ExecuteNonQuery());
if (result > 0)
{
ShowAlertMessage("Record Is Deleted Successfully");
grvEmployee.EditIndex = -1;
BindEmployeeData();
}
else
{
lblMessage.Text = "Failed";
lblMessage.ForeColor = System.Drawing.Color.Red;
BindEmployeeData();
}
}
catch (Exception ex)
{
ShowAlertMessage("Check your input data");
}
finally
{
CloseConnection();
DisposeConnection();
}
}
protected void grvEmployee_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grvEmployee.EditIndex = -1;
BindEmployeeData();
}
protected void grvEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grvEmployee.PageIndex = e.NewPageIndex;
BindEmployeeData();
}
protected void btnReset_Click(object sender, EventArgs e)
{
ClearControls();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
try
{
CreateConnection();
OpenConnection();
_sqlCommand.CommandText = "Sp_GridCrud2";
_sqlCommand.CommandType = CommandType.StoredProcedure;
_sqlCommand.Parameters.AddWithValue("@Event", "Update");
_sqlCommand.Parameters.AddWithValue("@FirstName", Convert.ToString(txtFirstName.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@LastName", Convert.ToString(txtLastName.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@PhoneNumber", Convert.ToString(txtPhoneNumber.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@EmailAddress", Convert.ToString(txtEmailAddress.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@Gender", Convert.ToString(txtGender.Text));
_sqlCommand.Parameters.AddWithValue("@datepicker", Convert.ToString(datepicker.Text));
_sqlCommand.Parameters.AddWithValue("@Designation", Convert.ToString(txtDesignation.Text));
_sqlCommand.Parameters.AddWithValue("@Grade", Convert.ToString(txtGrade.Text));
_sqlCommand.Parameters.AddWithValue("@Department", Convert.ToString(txtDepartment.Text));
_sqlCommand.Parameters.AddWithValue("@Status", Convert.ToString(txtStatus.Text));
_sqlCommand.Parameters.AddWithValue("@Dojstn", Convert.ToString(txtDojstn.Text));
_sqlCommand.Parameters.AddWithValue("@PAN", Convert.ToString(txtPAN.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@Qualifiction", Convert.ToString(txtQualifiction.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@Discipline", Convert.ToString(txtDiscipline.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@DateOfMarrige", Convert.ToString(txtDateOfMarrige.Text.Trim()));
_sqlCommand.Parameters.AddWithValue("@BloodGroup ", Convert.ToString(txtBloodGroup.Text));
_sqlCommand.Parameters.AddWithValue("@DomicileStates", Convert.ToString(txtDomicileStates.Text));
_sqlCommand.Parameters.AddWithValue("@EnteryMode", Convert.ToString(txtEnteryMode.Text));
_sqlCommand.Parameters.AddWithValue("@DOEinpresentGrade ", Convert.ToString(txtDOEinpresentGrade.Text));
_sqlCommand.Parameters.AddWithValue("@PresentOccumodationReq", Convert.ToString(txtPresentOccumodationReq.Text));
int result = Convert.ToInt32(_sqlCommand.ExecuteNonQuery());
if (result > 0)
{
ShowAlertMessage("Record Is Updated Successfully");
grvEmployee.EditIndex = -1;
BindEmployeeData();
ClearControls();
}
else
{
ShowAlertMessage("Failed");
}
}
catch (Exception ex)
{
ShowAlertMessage("Check your input data");
}
finally
{
CloseConnection();
DisposeConnection();
}
}
 

Answers (4)