xswzaq

For Delete: I have this code (below) for my bindingnavigatordelete but no matter what I click (Ys/No) it always delete the selected rows.

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

If MessageBox.Show("Do you really want to DELETE this record ", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.No Then

Me.Focus()

End If

End Sub

For Update: I got this query (below0, but it give me (Query Definitions Differ - the following errors were encountered while parsing the contents of the sql pane - unable to parse query text -- the query cannot be represented graphically in the diagram and criteria pane)

UPDATE DTL
SET INVY= :NAME, NO = :NO, PART= :NPART, QTY= :NDIFF,
VAR = :VAR, ACC = :ACC, DT = :NDT, CAUSE = :CAUSE
WHERE (INVY= :NAME)

Can anyone please point out what I did wrong


Re: Visual Basic Language Update/Delete/Insert

rkimble

It sounds like you're using the default Delete button behavior on the BindingNavigator. I think you need to setup your own logic for deleting the selected row(s) if you want to change this behavior (which means setting the BindingNavigator.DeleteItem = Nothing and then adding code to do the deletion in the Click event handler).

The query appears wrong as you do not appear to be using valid parameter names. For SQL Server, try using @ before the parameter name instead of :

INVY = @Name

No = @No

etc.

Hope that helps.






Re: Visual Basic Language Update/Delete/Insert

LL_ME

You are right, I am using the default Delete Button on the Navigator. With or without this line of code me.Me.BindingNavigatorDeleteItem = Nothing. The behavior is still the same. Should I create a deletebtn

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

If MessageBox.Show("Do you really want to DELETE this record ", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.No Then

Me.BindingNavigatorDeleteItem = Nothing

Me.Focus()

End If

End Sub

On the other one whether with an " : or @ ". It still have the same problem.

Thank you for helping.





Re: Visual Basic Language Update/Delete/Insert

rkimble

Sorry, you need to set the DeleteButton to None in the property window at design time. Then add code to the event handler to actually delete the record when the user chooses Yes in the dialog.

Try using the designer portion of the SQL query builder to write the query instead of typing it.

BTW, what kind of database is it If it is Access you can't use named parameters and they should all be question marks.






Re: Visual Basic Language Update/Delete/Insert

LL_ME

How to add code for event handler

it is oracle database, I did try the " :, , @" but none of them working correctly for me.





Re: Visual Basic Language Update/Delete/Insert

rkimble

The event handler for the DeleteItem.Click even might look something like:

Code Snippet

Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click

If MessageBox.Show("Are you sure you want to delete this record ", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then

Me.BindingSource1.RemoveCurrent()

End If

End Sub

This assumes that the BindingSource for the BindingNavigator is called BindingSource1.

I do not know what the correct parameter structure for Oracle is... In Sql Server the parameters are named like "@Param1" and in access they are named " ". You will need to see your Oracle documentation to find out what the correct syntax for paramters is.






Re: Visual Basic Language Update/Delete/Insert

LL_ME

Thank you rkimble

The Delete is now working.