how to delete a row in a gridview

Discussion in 'ASP' started by shyam_oec, Dec 22, 2009.

  1. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    hi,
    in a grid view i have enabled delete link,so that when a user clicks a delete link,corresponding row gets deleted from the database as well as from grid view.Data in the grid view is filled through coding,in the program using DataAdapter.
    So, how to do that?
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com
    This is the code that I've used in my program for this purpose.

    Code:
        Protected Sub DeleteSQLCode(ByVal sender As Object, ByVal e As EventArgs)
            Try
                Dim lnkRemove As LinkButton = DirectCast(sender, LinkButton)
                strSql = "delete from myreports where ID = @id"
                con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./App_Data/Reports.mdb") & ";User Id=admin;Password=;")
                com = New OleDbCommand(strSql, con)
                com.CommandText = strSql
                com.CommandType = CommandType.Text
                com.Parameters.Add("@id", OleDbType.Integer).Value = lnkRemove.CommandArgument
                com.Connection.Open()
                com.ExecuteNonQuery()
                com.Connection.Close()
                disp_myrep()
            Catch
                msg = "<h1 class=""ErrMsg"">Error Encountered: </h1>" & "<br/><b><font color=""red"">Error Source: " & Err.Source & "<br/>Error Description: " & Err.Description & "</font></b>"
            End Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
        End Sub
    
     
  3. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    769
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    http://techiethakkar.blogspot.com

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice