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