Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
i have table in sqlserver i want to delete rows through gridview using sqlserver in thnx in advance
Posted 29-Nov-12 19:54pm
__TR__ at 30-Nov-12 1:59am
This is not a good question. Use "Improve question" widget to update your question and provide more details on what is it you need help with.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use the following steps.
1) assign ID's (Primary Key) to Gridview
2) Use Gridview Row Deleting event.(using Command name)
3) Get the ID of row clicked by user to Delete.
4) Use ID in delete sql query & execute sql command.
5) Bind Gridview after successful deletion of row.
Use the following code.
protected void gvAcceptanceStatus_RowDeleting(object sender, GridViewDeleteEventArgs e)
        string ObvID =gvAcceptanceStatus.Rows[e.RowIndex].Cells[3].Text.ToString();
               string ObvID=gvAcceptanceStatus.DataKeys[index].Values["ObservationID"].ToString();
            SqlCommand cmd = new SqlCommand("sp_DeleteInfo", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            catch (Exception ex)
                throw new Exception("Exception adding account. " + ex.Message);
In aspx page:-
  <asp:gridview id="gvAcceptanceStatus" runat="server" autogeneratecolumns="False" datakeynames="ObservationID" onrowdeleting="gvAcceptanceStatus_RowDeleting">
Convert it to VB.NET.
Hope this helps. Smile | :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 260
2 Sergey Alexandrovich Kryukov 220
3 DamithSL 208
4 Dave Kreskowiak 200

Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid