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. why no delete?

why no delete?

Scheduled Pinned Locked Moved Visual Basic
databasesharepointsysadminhelpquestion
4 Posts 2 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
    boyindie
    wrote on last edited by
    #1

    Hi I have writing the followin function which catches a datagrid link button event, which should take the user id from the selected record and pass it into a stored procedure, and then refresh page, with the selected record deleted. It all seems to work perfectly fine, but it jus doesn't delete for the some reason I have also ran the procedure through a command window and that works as expected here is my code for dealing with the button click and passing the parameter into the stored procedure any help or spotting of my retarded mistake would be much appreciated cheers boyindie Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgPriv.ItemDataBound Dim l As LinkButton If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then l = CType(e.Item.Cells(6).FindControl("cmdDel"), LinkButton) l.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this item?');") End If End Sub Sub dgpriv_ItemCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.ItemCommand Dim iid As Integer = dgPriv.DataKeys(e.Item.ItemIndex) 'Grab the ID from the hidden column Dim litErr As New Literal Dim myConnection As New MySqlConnection("Server=localhost; ;database=test;") Try Dim param As New MySqlParameter Dim myDeleteCommand As MySqlCommand = New MySqlCommand("sp_mydelete", myConnection) myDeleteCommand.CommandType = CommandType.StoredProcedure param = myDeleteCommand.Parameters.Add("?p_id", MySqlDbType.VarChar) param.Direction = ParameterDirection.Input param.Value = iid myConnection.Open() 'Open the connection myDeleteCommand.ExecuteNonQuery() 'Delete the record myConnection.Close() 'Close the connection Catch ex As Exception litErr.Text = ex.Message MsgBox(ex.Message) End Try refresh() End Sub and this is my asp code

    R 1 Reply Last reply
    0
    • B boyindie

      Hi I have writing the followin function which catches a datagrid link button event, which should take the user id from the selected record and pass it into a stored procedure, and then refresh page, with the selected record deleted. It all seems to work perfectly fine, but it jus doesn't delete for the some reason I have also ran the procedure through a command window and that works as expected here is my code for dealing with the button click and passing the parameter into the stored procedure any help or spotting of my retarded mistake would be much appreciated cheers boyindie Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgPriv.ItemDataBound Dim l As LinkButton If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then l = CType(e.Item.Cells(6).FindControl("cmdDel"), LinkButton) l.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this item?');") End If End Sub Sub dgpriv_ItemCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) Handles dgPriv.ItemCommand Dim iid As Integer = dgPriv.DataKeys(e.Item.ItemIndex) 'Grab the ID from the hidden column Dim litErr As New Literal Dim myConnection As New MySqlConnection("Server=localhost; ;database=test;") Try Dim param As New MySqlParameter Dim myDeleteCommand As MySqlCommand = New MySqlCommand("sp_mydelete", myConnection) myDeleteCommand.CommandType = CommandType.StoredProcedure param = myDeleteCommand.Parameters.Add("?p_id", MySqlDbType.VarChar) param.Direction = ParameterDirection.Input param.Value = iid myConnection.Open() 'Open the connection myDeleteCommand.ExecuteNonQuery() 'Delete the record myConnection.Close() 'Close the connection Catch ex As Exception litErr.Text = ex.Message MsgBox(ex.Message) End Try refresh() End Sub and this is my asp code

      R Offline
      R Offline
      RepliCrux
      wrote on last edited by
      #2

      Your current code seems to be right, the only reason I can think of is you have done some silly mistake in your stored procedure. Did you debug the code? Does it get the iid value you want to delete? If it gets through your myDeleteCommand.ExecuteNonQuery() line without any exception, it bound to be the stored procedure.

      B 1 Reply Last reply
      0
      • R RepliCrux

        Your current code seems to be right, the only reason I can think of is you have done some silly mistake in your stored procedure. Did you debug the code? Does it get the iid value you want to delete? If it gets through your myDeleteCommand.ExecuteNonQuery() line without any exception, it bound to be the stored procedure.

        B Offline
        B Offline
        boyindie
        wrote on last edited by
        #3

        ah the joys of copy and pastin previous code and forgettin to change the database name to the one you want to use! It was working fine it was jus using the procedure of the same name in the wrong database! cheers for your help

        B 1 Reply Last reply
        0
        • B boyindie

          ah the joys of copy and pastin previous code and forgettin to change the database name to the one you want to use! It was working fine it was jus using the procedure of the same name in the wrong database! cheers for your help

          B Offline
          B Offline
          boyindie
          wrote on last edited by
          #4

          I don't suppose you know how to bind data to a textbox I have been trying to find a way of taking a value from a select statement and binding it to a textbox, should be so easy but can't find a method to do it!

          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