Click here to Skip to main content
12,624,895 members (36,679 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
i have table in sqlserver i want to delete rows through gridview using sqlserver in vb.net thnx in advance
Posted 29-Nov-12 20:54pm
Comments
__TR__ 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
 
good
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();
//OR
               string ObvID=gvAcceptanceStatus.DataKeys[index].Values["ObservationID"].ToString();
            conn.Open();
            SqlCommand cmd = new SqlCommand("sp_DeleteInfo", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("ID",ObvID);
        
            
            try
            {
 
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Exception adding account. " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
            BindgvAcceptanceStatus();
            
        }
In aspx page:-
<asp:gridview id="gvAcceptanceStatus" runat="server" autogeneratecolumns="False" datakeynames="ObservationID" onrowdeleting="gvAcceptanceStatus_RowDeleting">
Convert it to VB.NET.

Hope this helps. :)
  Permalink  
v4

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100