Hi,
I am a beginner in using visual basic 2005 express edition. And I went through the tutorials. But when coming to 'Connecting to an Existing Database' part, I encounter the problem which I am not able to update the changes to the database. When i tried to delete a record, the change is not made to the database. So everytime when i press F5 again, the data will be get back to the old one.
I understand that the program keeps two sets of data in project dir and bin dir. So I follow someone's suggestion which is connect to remote database directly without keeping any copy in my project folder. (By selecting 'no' when prompt for copy the data to local dir) .
But now i have this problem and cannot proceed. I drag the table called POS into an empty form, Then there is a menu bar shown up automatically with 'next', 'new', 'delete' and 'save' button on it. When i press 'save', err will occur.
The code below is generated by the IDE itself.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Public
Class Form1 Private Sub POSBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles POSBindingNavigatorSaveItem.Click Me.Validate() Me.POSBindingSource.EndEdit() Me.POSTableAdapter.Update(Me.POSDataSet.POS) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'POSDataSet.POS' table. You can move, or remove it, as needed. Me.POSTableAdapter.Fill(Me.POSDataSet.POS) End SubEnd
Class/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The line highlighted in yellow is the one which problem occurs. The err message title is System.InvalidOperationException was unhandled
content is:
Update requires a valid deletecommand when passed DataRow Collection with deleted rows.
(because i deleted one row then click on save button)
I am not sure what does it mean. Please help... Forgot to mention my remote database is an Access database.
Thank you so much.

I have problem with the tutorial.
Ameabaspy
Hi,
Thanks for the help. But I connect to a Access database in another folder, and the database is very simple having only one table inside. I am not sure where i went wrong because i am following exactly the steps guided in the tutorial. What i did is quite simple
1.Add a new data source in the Data Sources window. Clicking no for not copy the database to the project. So i can change the data remotely.
2. Drag the datatable into my form. So that there will be a binding navigator and a datagrid come out.
This is all what i did, I can add the data to the database and when click save, the change will be saved.
However, when i delete one row then click save, there will be a run time error which i described above.
I think this is supposed to be simple. Am i having this error because visual basic is not able to work with remote Access database But then i can still add in data into my remote database.
Best regards.
sharpej
hi,
I have checked the faq, there are posts on how to solve the problem of not able to save the changes to the database, meaning how to get the changes to dataset reflected to the actual database.
I am using a remote database, so i dun have the problem of keeping two sets of data. Whatever the change will be write to the only one database. I am able to insert into the table in my form and save the changes. However, When i try to save a deletion, error will occur and ask me to give to specific delete command, and my code
Me.POSTableAdapter.Update(Me.POSDataSet.POS)
is high-lighted.
I go and check the TableAdapter, under properties my deleteCommand is none. I tried to build a delte query to delete the current row. But not able to do so, not sure what shall i put in the commandText.
(Thought it will be something like : "Delete from POS where Current of POS" but doesn't work)
So i left the deleteCommand to be none and then wrote a piece of code, hopefully can overwrite the default delete command provided by the binding navigator.
Private
Sub POSBindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click If MessageBox.Show("Are you sure ", "", MessageBoxButtons.YesNo)= Windows.Forms.DialogResult.Yes ThenPOSBindingSource.RemoveCurrent()
End If End SubBut it turns out that the program still prompt me for error when i click on save. Same error still exist.
Desperate now..... Please help.
Victor Spencer
hi,
at the top of this forum t here is a FAQ thread has a question like your
hope this helps
Upsilon
Only if you specifically ask it to when using the designer wizard. By default its select only.
Zhiqiang
hi,
express edition doesn't support remote database and what you talk about is not the case
i have just tried it the way i told you, and its working here, the database is not in the project folder, have one table , i can delete rows and save normaly without any problem, sounds like you did something in your designer ,try to creat a new project and see
hope this helps
sjnaughton
hi,
creat a database that has a single table and try to delete and use save buttons it will work and will delete if you don't have any other problem
most of us when we build a relational database we don't use force cascading update and cascading delete and they are not selected by default because its very dangerous so if you tried to delete a row that has children in other table simply the database will reject for data integrity and not to creat orphan rows
you have 2 options both of them are dangrous
1) in your database designer force the cascading delete b4 you build the dataset
2) open your dataset designer select the relation between 2 tables go to properties at bottom you will find edit relation it will open a new window at bottom set your constrant and allow cascading delete
but note : creat a table adapter for the child table and make it to fill the table when the form is loaded and to update when you click save b4 your parent table adapter to update if you didn't edit the constraint in the database itself
hope this helps
Umair Khan
Hi,
When I use the binging navigator by drag and drop the datatable in a form, I can only add in data, addition will be saved eventually but not for deletion.
I am connecting to a remote Access database so there is no problem as not able to save the change due to the system keeping two copies of the database. (As i read through the forum, a lot people have the problem which, the changes made to the dataset are not updated in the database, this is not my problem.)
I can add new data to my database and save the change, but when i delete a row of data, and click save button on the binding navigator, there will be a run time error says i need a proper delete command. so I opened up the tableAdapter designer and go and add the delete query into the properties window of tableAdaptor using query builder. This is where i can not proceed.
I want to delete the selected row of data and then save the change.
What shall i put into the CommandText box in order to get my deletion saved everytime when i click the save button Or there are some other ways to do it
As when i follow the tutorial provided by Visual Basic 2005 Express, It seems very simple that by clicking on the save button on the binding navigator, the changes to the the dataset will be updated to your database as long as you set to copy newer.... And no code is to be written. But it turns out very complicated. So frustrating....
SRJohnson
Hi,
Thanks for your response. I solved my problem now.
I added some sql code for deletion and update in my tableAdapter using the query builder. I thought this is supposed to be generated by the IDE itself when i create binding navigator.
Best Regards,
basara
Mr. Lane
hi,
its not good to ask a question twice , if you weren't able to reach to your thread you can use "MyThreads" link at the top of this webpage
i will merge both of your threads
best regards