Delete Button Not Working

rashaadbryan246

New member
Joined
Aug 21, 2015
Messages
1
Programming Experience
Beginner
hi so i have a basic form connected to a database to connect to a database, now my problem is that when i press delete it deletes from the datagridview but not from the actual database and yes i am checking the database in the debug folder also after I use the delete button when add a new row to the database and click save the program crashes and i get the error Concurrency violation: the DeleteCommand affected 0 of the expected 1 records

Save button code

01Private Sub btnSave_Click_1(sender As Object, e As EventArgs) Handles btnSave.Click

02

03 Try

04 Me.Validate()

05 Me.InterimStorageOrdersBindingSource.EndEdit()

06 Me.Interim_Storage_OrdersTableAdapter.Update(Me.Stock_ManagerDataSet.Interim_Storage_Orders)

07 MsgBox("Update successful")

08

09 Catch ex As Exception

10 MsgBox("Update failed")

11 End Try

12

13 End Sub





Delete Button Code
1Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

2 InterimStorageOrdersBindingSource.RemoveCurrent()

3 End Sub
 
You have successfully made your code difficult to read. Please post code snippets using code formatting tags, i.e.

[xcode=vb]your code here[/xcode]

or, if you need the option for custom formatting:

[code]your code here[/code]
 
You have a Save method that you presumably use to save inserts and updates back to the database. You have to save deletes in exactly the same way. Calling Update on your table adapter saves all the changes from the DataTable back to the database, which includes inserts, updates and deletes. Just as an insert or update only affects the local DataTable until you explicitly save that change back to the database, so does a delete.
 
hi so i have a basic form connected to a database to connect to a database, now my problem is that when i press delete it deletes from the datagridview but not from the actual database and yes i am checking the database in the debug folder also after I use the delete button when add a new row to the database and click save the program crashes and i get the error Concurrency violation: the DeleteCommand affected 0 of the expected 1 records

Save button code

01Private Sub btnSave_Click_1(sender As Object, e As EventArgs) Handles btnSave.Click

02

03 Try

04 Me.Validate()

05 Me.InterimStorageOrdersBindingSource.EndEdit()

06 Me.Interim_Storage_OrdersTableAdapter.Update(Me.Stock_ManagerDataSet.Interim_Storage_Orders)

07 MsgBox("Update successful")

08

09 Catch ex As Exception

10 MsgBox("Update failed")

11 End Try

12

13 End Sub





Delete Button Code
1Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click

2 InterimStorageOrdersBindingSource.RemoveCurrent()

3 End Sub
Holy crap that's impossible to read, try using the [xcode=vb]Your code here[/xcode] tags so we can read it, it'll make your code look like this:
Private Sub btnSave_Click_1(sender As Object, e As EventArgs) Handles btnSave.Click
    Try
    Catch ex As Exception
    End Try
End Sub
 
Back
Top