Answered by:
delete from database

Question
-
User-1325166946 posted
i would like to ask how im going to delete a record in database by clicking a delete button and automatically refresh and show it to a GridView ..
can someone please help me .. thank you
Wednesday, October 5, 2011 12:11 PM
Answers
-
User-1516073966 posted
Hi,
Refer the link http://www.dotnetspider.com/resources/42807-How-edit-or-delete-database-record-using-grid.aspxFollowing is the sample click event.
protected void btnDelete_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "deleteRecord"; //here delte record is a stored procedure. cmd.Parameters.AddWithValue("@Id", 1); //Here @Id is the stored procedure parameter and 1 is the value which is hardcoded for sample. cmd.ExecuteNonQuery(); //Here in bind grid method get the data from the db and rebind to grid view. BindGrid(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 5, 2011 12:19 PM -
User1784393945 posted
Hey try this code it will help you
protected void grd_data_RowDeleting(object sender, GridViewDeleteEventArgs e) { bool chk = obj.delete_rec(Convert.ToInt64(grd_data.DataKeys[e.RowIndex].Value.ToString())); if (chk == true) { empty(); bind_grid(); objmsg.msg("Deleted successfully"); } else { objmsg.msg("system busy, try again later"); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 6, 2011 4:12 AM
All replies
-
User-1516073966 posted
Hi,
Refer the link http://www.dotnetspider.com/resources/42807-How-edit-or-delete-database-record-using-grid.aspxFollowing is the sample click event.
protected void btnDelete_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "deleteRecord"; //here delte record is a stored procedure. cmd.Parameters.AddWithValue("@Id", 1); //Here @Id is the stored procedure parameter and 1 is the value which is hardcoded for sample. cmd.ExecuteNonQuery(); //Here in bind grid method get the data from the db and rebind to grid view. BindGrid(); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, October 5, 2011 12:19 PM -
User1784393945 posted
Hey try this code it will help you
protected void grd_data_RowDeleting(object sender, GridViewDeleteEventArgs e) { bool chk = obj.delete_rec(Convert.ToInt64(grd_data.DataKeys[e.RowIndex].Value.ToString())); if (chk == true) { empty(); bind_grid(); objmsg.msg("Deleted successfully"); } else { objmsg.msg("system busy, try again later"); } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, October 6, 2011 4:12 AM -
User3866881 posted
i would like to ask how im going to delete a record in database by clicking a delete button and automatically refresh and show it to a GridView ..An easy way is that you can directly drag and drop a GridView onto the page, and then drag and drop an AccessDataSource onto the page too. And then configure the connection in the AccessDataSource according to its Wizard to auto-genrate Insert/Delete/Update methods, and then bind the AccessDataSource to the GridView. In the end, please Enable "AutoGenerateEditButton".
A full code sample can be seen at: http://www.asp.net/data-access/tutorials/inserting-updating-and-deleting-data-with-the-sqldatasource-vb
Thursday, October 6, 2011 10:18 PM