Click here to Skip to main content
Rate this: bad
good
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 vb.net thnx in advance
Posted 29-Nov-12 20:54pm
Comments
__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
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. Smile | :)
  Permalink  
v4

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

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 235
2 Afzaal Ahmad Zeeshan 154
3 Sergey Alexandrovich Kryukov 147
4 BillWoodruff 135
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
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