Step 1) Bind Grid Data Where One field Contain Record ID.
Step 2) Add below code on RecordId Click Event.
https://developerprob.blogspot.in/2016/07/user-registration-application-using-c.html
Step 4) After that add below code on DataBase Layer class Add below method-
Step 6) After Successful Completion of Above Code Record deleted from database.
Step 2) Add below code on RecordId Click Event.
Step 3) Use Bussiness object as Previous Post Bussiness Object Class.protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e){int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());BusinessObject bo = new BusinessObject();bo.Id = id;try{int retVal = objDAL.DeleteProjRecord(bo);if (retVal > 0){lblmessage.Text = "Record deleted successfully";lblmessage.ForeColor = System.Drawing.Color.Green;}else{lblmessage.Text = "Book details couldn't be deleted";lblmessage.ForeColor = System.Drawing.Color.Red;}}catch (Exception ex){Response.Write("Oops! error occured :" + ex.Message.ToString());}}
https://developerprob.blogspot.in/2016/07/user-registration-application-using-c.html
Step 4) After that add below code on DataBase Layer class Add below method-
Step 5) Use Below stored Procedure for delete record from database.SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestProj;Integrated Security=True");public Int32 DeleteProjRecord(BusinessObject objBEL){int result;try{SqlCommand cmd = new SqlCommand("DeleteRecord", con);cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.AddWithValue("@id", objBEL.Id);if (con.State == ConnectionState.Closed){con.Open();}result = cmd.ExecuteNonQuery();cmd.Dispose();if (result > 0){return result;}else{return 0;}}catch (Exception ex){throw;}finally{if (con.State != ConnectionState.Closed){con.Close();}}}
BEGIN
DELETE FROM Emp WHERE id = @id
END
No comments:
Post a Comment