Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Delete Record in datagrid not working

Delete Record in datagrid not working

Scheduled Pinned Locked Moved Visual Basic
databasecsshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BORN again
    wrote on last edited by
    #1

    Hi , I have a datagrid in which I have a button column 'Delete' that works by calling 'Ondatagrid_deleteCommand'. My problems is when I try to delete a record by clicking on 'Delete' button in datagrid, I get the following error "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index " I am clueless as to why this is happening since the same routine is working in other application which is exactly similar and ofcourse in which I am using a datagrid. The sub for delete command is as follows: ************************************************************************************************** Sub DataGrid_DeleteCommand(sender As Object, e As DataGridCommandEventArgs) 'Create the objects for the connection Dim myConnection As New SqlConnection(ReadDBConnectionString()) Dim DeleteCommand As SqlCommand = new SQLCommand() Dim Transaction as SQLTransaction 'Define the Query DeleteCommand.CommandText = "DELETE from chequedata where cheqregno= " &DataGrid.DataKeys(e.Item.ItemIndex) 'Add the Parameters to the Query with the actual Value DeleteCommand.Connection = myConnection 'Start Try Block Try 'Open Connection myConnection.Open() 'Begin Transaction Transaction = myConnection.BeginTransaction() 'Tell Command Object which Transaction to use DeleteCommand.Transaction = Transaction 'Execute the SQL Command DeleteCommand.ExecuteNonQuery() 'Nothing happend - Commit Transaction Transaction.commit() 'Show Message in Label lblMessage.Text = "Entry deleted" catch ex as Exception 'Failure occured - Rollback Transaction Transaction.RollBack() 'Write Message in Label lblMessage.Text = "Entry Not deleted" Finally 'Close connection myConnection.Close() DataGrid.EditItemIndex = -1 'Refresh the Grid and show changes RefreshGrid(Cint(ddlBranch.SelectedITem.Value),txtsearch.text) End Try End Sub *************************************************************************************************** Thankyou all for all the help. It is much appreciated. Aartee. ...HE is watching Us All!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups