Question:
I've searched for this and found answers but it doesn't work for me. I'm trying to do a very simple thing. I have an application with 1 form that shows customer information using the binding navigator and nothing I do actually adds any data to the database. As long as I keep the application open it looks like it updates and I can navigate back and forth to the records I've added but as soon as I close the application then reopen the application it only shows the 1 record in the database that I added directly in Access? I'm really baffled with this.
Answer1:
Are you using a line of code like the following in a FormClosing event handler?
this
.yourTableAdapter.Update(this.yourDataSet.YourTable);
If you aren't, try your equiavalent of the line in the FormClosing event handler and you may find it works.
Daniel B. - Please mark solutions as answers (everyone then knows the thread has been resolved)
Answer2:
That's what I have. In fact I have this.
RowsSaved = this.tableadapter.update(this.dataset.tablename)
and rowssaved is always zero.
Answer3:
From what you say, you might have encounted a thorny issue that's going to take some investigating to resolve.
Before we get into that, I just want to be absolutely sure there is nothing obvious wrong, such as a mismatch in dataset's.
With this in mind, please can you post the follwowing items (please post your actual code where requested):
-
In your FormLoad event handler, the line of code used to fill the dataset table.
-
The name of the BindingSource specified in the BindingNavigator.
-
The DataSource and DataMember from the BindingSource in step 2.
-
The line of code from the FormClosing event you are using to try and save database changes.
While gathering this information, you may spot a mismatch yourself and hey presto, problem resolved.
Daniel B. - Please mark solutions as answers (everyone then knows the thread has been resolved)
Answer4:
Daniel B· wrote: |
|
From what you say, you might have encounted a thorny issue that's going to take some investigating to resolve.
Before we get into that, I just want to be absolutely sure there is nothing obvious wrong, such as a mismatch in dataset's.
With this in mind, please can you post the follwowing items (please post your actual code where requested):
-
In your FormLoad event handler, the line of code used to fill the dataset table.
Me .CustomersTableAdapter.Fill(Me.InvoicingDataSet.Customers)
-
The name of the BindingSource specified in the BindingNavigator. CustomersBindingSource Customers
-
The DataSource and DataMember from the BindingSource in step 2. InvoicingDataSet
-
The line of code from the FormClosing event you are using to try and save database changes.
Me.CustomersTableAdapter.Update(Me.InvoicingDataSet.Customers)
While gathering this information, you may spot a mismatch yourself and hey presto, problem resolved. | |
Answer5:
Ok, thanks.
I think I've found the likely cause (famous last words
).
Do you by any chance have the following line of code before the TableAdaptor Update call?
Me.InvoicingDataSet.AcceptChanges()
If so, change the line to the following and you should find it fixes things.
Me.CustomersBindingSource.EndEdit()
Calling AcceptChanges is not appropirate here and causes the DataSet to lose track of the row changes that have been made.
The replacement line ensures any changes made to the current record are saved.
Daniel B. - Please mark solutions as answers (everyone then knows the thread has been resolved)
Answer6:
Actually, I've already been down that road with failure. I put the following code into the formclosing event and even though it shows that 1 row was saved, when I look at the database table the data hasn't changed.
Me.Validate()
Dim ROWSSAVED As Integer
Me.CustomersBindingSource.EndEdit()
ROWSSAVED =
Me.CustomersTableAdapter.Update(Me.InvoicingDataSet.Customers)
rowssaved always says 1 after the update but with no data change.
Answer7:
You may have already done this, but if you added the actual database to your project, have you changed the "Copy To Output Directory" property to "Copy if newer" (right click the database in Solution Explorer to see the properties)?
I did also check what would happen if either the ODBC data source or the file itself was read-only and as you would expect you get an exception when you call Update. At least this can be ruled out.
Daniel B. - Please mark solutions as answers (everyone then knows the thread has been resolved)
Answer8:
That was the problem. So what's with that. This is the first vb.net project I've worked on and I can't believe I was trapped by something so simple. I do see that there is an identical database in the solution directory one above where the project is. So basically, everytime I started up the application it was copying the original version of the database back to the project folder. Well, lesson learned. Thanks for your help. I never would've found that, I would've been pulling my hair out. Finally, I can move forward.
Regards,
Carl Cioffi