Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6748791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:36:32+00:00 2026-05-26T12:36:32+00:00

This code is intended to grab the ID of the deleted record, the user

  • 0

This code is intended to grab the ID of the deleted record, the user who deleted the record, and the date and time the record was deleted and insert it into a hostical table.

So far, once a record is deleted, the code grabs more than one deleted record.

Please see my code and what I am doing wrong.

Thanks alot in advance for your help.

    Protected Sub GridView1_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles GridView1.RowDeleted 
    Dim connStr As String = ConfigurationManager.ConnectionStrings("Constr").ConnectionString 
    Dim cnn As SqlConnection 
    Dim cmd As SqlCommand 
    Dim sql As String = "" 

    ' Indicate whether the delete operation succeeded.  

        If e.Exception Is Nothing Then 

            Dim strID As String = GridView1.FindControl("ID").Cells(1).Text 
            'Who deleted a record? 
            sql += "Insert into Archives ([ID],[choice],[date_stamp],[approved],[chcknum],[DeletedBy],[dateDeleted]) " 
            sql += " SELECT [ID],[choice],[date_stamp],[approved],[chcknum],[login],getDate() from Depends " 
            sql += " inner join  Emp on Depends.employee_id = Emp.employee_id where login ='" & Session.Item("UserName").ToString & "' and upass = '" & Session.Item("Password").ToString & "' and [ID] = '" & strID & "' " 
        End If 
    Response.Write(sql) 
    Response.End() 
    Try 
        cnn = New SqlConnection(connStr) 

        cnn.Open() 
        cmd = New SqlCommand(sql, cnn) 

        cmd.ExecuteNonQuery() 
        cmd.Dispose() 
        sql = "" 
    Catch ex As SqlException 
        Dim errorMsg As String = "Error in Updation" 
        errorMsg += ex.Message 
        Throw New Exception(errorMsg) 
    Finally 
        cnn.Close() 
    End Try 
End Sub

My problem, I think, lies in this line of code:

Dim strID As String = GridView1.FindControl(“ID”).Cells(1).Text

I don’t think it is correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:36:32+00:00Added an answer on May 26, 2026 at 12:36 pm

    I’m guessing you’re looking for the GridView.DataKeys property. Use it to tell your GridView which column(s) in the data is should use as an unique identifer.

    You probably also want to look into a few other optimzations for your code:

    • Use parameters in your query, don’t concatenate a SQL statement like that.
    • Use the Using statement with your SqlConnection and SqlCommand objects for proper and easy disposal.
    • You’re not achiving anything with the try-catch, in fact you’re obscuring the exception stack.

    Update:

    See the GridViewDeletedEventArgs.Keys Property to get the ID of the deleted row. Is the “ID” column part of the query you’re using to bind the GridView?

    Here’s a better (complete) example:

    .aspx:

    <asp:GridView ID="GridView1" DataKeyNames="ID" AutoGenerateDeleteButton="true" runat="server">
    </asp:GridView>
    

    Code-behind, with some dummy data:

    Public Class _Default
      Inherits System.Web.UI.Page
    
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
          Dim x() = {New With {.id = 1, .name = "xxx"}, New With {.id = 2, .name = "zzz"}}
          GridView1.DataSource = x
          GridView1.DataBind()
        End If
      End Sub
    
      Private Sub GridView1_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim id As Integer = CInt(e.Keys(0))
        ' Do your stuff!
        ' Don't forget to rebind the GridView, it will still have the deleted row in Viewstate.
      End Sub
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code here, which is intended to allow any type of arguments:
is there a way to make this code work as intended? #include <iostream> using
This code doesn't work as intended, what am I doing wrong? $(document).ready(function(){ $(a.hide-para).click(function(){ $('p').hide();
I am writing some code intended to translate ambiguous DNA codes into possible amino
This is the code that is intended to fetch up the email from Gmail
This code does not upload the intended value to the database. I was expecting
This code compiles, links and works as intended: #include <QApplication> #include <QListView> #include File_List_Model.h
I wonder if this code always works as intended: var a = [0, 1];
This code fails when I try to debug it using VC2010: char frd[32]=word-list.txt; FILE
This code builds without problems but fails when executed: var query = _db.STEWARDSHIP .OrderByDescending(r

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.