Delete a row from gridview in back end c#

Launcelot

New Member
I am trying to delete a gridview row in the back end. When I click 'delete' it deletes from the gridview, however it does not delete from the database. Can anyone see why this may be? My code is as follows:\[code\]protected void GVMyBookings_DeleteBooking(object sender, GridViewDeleteEventArgs e){string connstring = ConfigurationManager.ConnectionStrings["BookingConn"].ToString();SqlConnection MyConnection = new SqlConnection(connstring);MyConnection.Open();SqlDataSource SDSStudents = new SqlDataSource();SDSStudents.DeleteCommand = "DELETE * FROM Tbl_Booking WHERE ID=@BookingID_PK";SDSStudents.DeleteParameters.Add("@BookingID_PK", GVMyBookings.Rows[e.RowIndex].Cells[0].ToString());SDSStudents.ConnectionString = connstring;GVMyBookings.DataSource = SDSStudents;GVMyBookings.DataBind();MyConnection.Close();MyConnection.Dispose();}\[/code\]Many Thanks
 
Back
Top