I have tried to delete a row in a table.But it was saying error as in the following way.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 74: protected void EmployeeGridView_RowDelete(object sender, GridViewDeleteEventArgs e)
Line 75: {
Line 76: int empid = Convert.ToInt32(((TextBox)EmployeeGridView.Rows[e.RowIndex].FindControl("txtempid")).Text);
in line 76 ,it was saying that error.
Please tell me solution rectify the error
I have written code for deleting was as like below
protected void EmployeeGridView_RowDelete(object sender, GridViewDeleteEventArgs e)
{
int empid = Convert.ToInt32(((TextBox)EmployeeGridView.Rows[e.RowIndex].FindControl("txtempid")).Text);
string connectionstring = @" Data Source=01HW235982\SQLEXPRESS2008;Initial Catalog=adarsh;Persist Security Info=True;User ID=sa;Password=Pass@123";
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("DeleteEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@emp_id ", empid);
cmd.ExecuteNonQuery();
FillGrid();
}
Please tell me the solution