How can I save data entered in a dataset via the UI? I tried the code suggested in the "VB Guided Tour", Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Me.AddressesBindingSource.EndEdit() Me.AddressesTableAdapter.Update(Me.SQLdbDataSet.Addresses) End Sub
but all changes are lost when I restart the application.
Thanks. |
| Mable Thursday, November 10, 2005 4:39 AM |
Found the solution in the free downloadable book 'Build a program now' at the 'Registration Benifit Program' p154 (text in blue). In brief there are 2 copies of the database: 1 in the application folder and 1 in the bin\debug folder. At design time the database in the app folder is used while at run time the other one. By default in the solution explorer the database is set to COPY ALWAYS to the bin\debug folder which means that the database is alwys overwritten by the one in the application folder. Solution: You can change this property to DO NOT COPY and copy it yourself if when needed or leave the database out of the project. When asked to bring it in the project when creating a connection, sympy say no. I hope you are as pleased as I am now to have found that annoyance. |
| Frank De Koninck Friday, November 11, 2005 3:35 PM |
I believe AddressesTableAdapter.Update invokes the AddressTableAdapter.UpdateCommand. Prior to calling Update you'll need to set AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand...
Hope this helps, Hal |
| HalW MSFT Thursday, November 10, 2005 8:03 PM |
I have the same problem in C# even if you don't use a tableAdapter but a sqlCommand object instead. Though affectedRecords reflects the correct rows affected. |
| Frank De Koninck Thursday, November 10, 2005 4:29 PM |
|
| VeSO Thursday, November 10, 2005 5:02 PM |
I believe AddressesTableAdapter.Update invokes the AddressTableAdapter.UpdateCommand. Prior to calling Update you'll need to set AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand...
Hope this helps, Hal |
| HalW MSFT Thursday, November 10, 2005 8:03 PM |
Thanks. But I guess I'm too new to this to understand your suggestion. I added a line,
AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand
just before the update, but that just generated two compiler errors:
Error 1 'UpdateCommand' is not a member of 'VBdatabase.SQLdbDataSetTableAdapters.AddressesTableAdapter'.
Error 2 Type 'SQLUpdateCommand' is not defined.
What am I missing?
Thanks.
|
| Mable Friday, November 11, 2005 4:54 AM |
Found the solution in the free downloadable book 'Build a program now' at the 'Registration Benifit Program' p154 (text in blue). In brief there are 2 copies of the database: 1 in the application folder and 1 in the bin\debug folder. At design time the database in the app folder is used while at run time the other one. By default in the solution explorer the database is set to COPY ALWAYS to the bin\debug folder which means that the database is alwys overwritten by the one in the application folder. Solution: You can change this property to DO NOT COPY and copy it yourself if when needed or leave the database out of the project. When asked to bring it in the project when creating a connection, sympy say no. I hope you are as pleased as I am now to have found that annoyance. |
| Frank De Koninck Friday, November 11, 2005 3:35 PM |
Thanks! I thought there must be a setting somewhere that I was missing. I find that if I set the copy property to "do not copy" I get an unhandled exception whenever I try to open the dataset. But "copy if newer" works just fine. The only problem is remembering to copy from App\bin\debug to App when needed. |
| Mable Friday, November 11, 2005 8:46 PM |
I must have missed something in the documentation. Everytime I would run this program The data would disappear. Thanks for pointing out that there are two copies.
|
| davechad Friday, December 16, 2005 8:20 PM |
This definitely sounds like my problem. I hate to show my ignorance but can you tell me how I change these options?
Thanks, |
| DesperadoMike Thursday, January 12, 2006 2:57 AM |
can u plz explain what the command in UpdateCommand and how to make this cuz adressTableadapter.update has to return a value in int
thanks
I believe AddressesTableAdapter.Updateinvokes the AddressTableAdapter.UpdateCommand. Prior to calling Update you'll need to set AddressesTableAdapter.UpdateCommand = new SQLUpdateCommand...
Hope this helps,
Hal |
| GOOOGO Monday, April 10, 2006 12:33 PM |
Hi all !
Man, forget all !!!
If u using a bindindsource, verify your's components databindings. If they connected direct from dataset the updates not work. Bind using bindingsource object and done!
Sorry my english!!!
I hope helpful. |
| Ricardo Oliveira Friday, April 28, 2006 7:18 PM |
Hi Guys, ran into the same problem last night and wasted 2 hours trying to figure out what was wrong.
As was posted above, this issue can be fixed by clicking on the database in the solution explorer and adjusting the property to read 'Copy if Newer' instead of 'Copy Always'. If you set it to 'Do Not Copy', you need to manually copy it or you an exception saying that it can't find the database file.
Thanks again to all who figured this out.
|
| russr Wednesday, May 24, 2006 5:38 PM |
Nice one, spent days scratching my head over this one, thanks
|
| TheBilly Saturday, May 27, 2006 11:08 PM |
I'm having a similar issue wher the data is not updating. I don't have a local copy of the database at all. I'm connecting to a remotly hosting SQL Server 2005 database. Everything was working fine until yesterday and now it's as if the tables are all read-only. The TableAdapter.Update command never invokes the underlying Update method. The underlying update method that should be invoked is
public virtual int Update(DataTable dataTable) {
return this.Adapter.Update(dataTable);
}
I set a breakpoint on the code and it never hit! ANyone have a clue why this would be?? |
| DerikJ Monday, June 05, 2006 5:55 PM |
"Found the solution in the free downloadable book 'Build a program now' at the 'Registration Benifit Program' p154 (text in blue)."
Where can I download this book? I to am having problems with the TableAdapter. My problem is when I try to update it tells me that .update is nota member of my workbook.
Thank you
Tom
|
| Tom Hallmark Sunday, July 23, 2006 5:27 PM |
Thanks Frank so much.. I lost my head couple of hours to find out what is happening. It works now, thanks again. |
| Codecredible Tuesday, August 01, 2006 5:17 PM |
I also have a problem updating the database:
I manually changed the datapath so I'm working directly on the database and for my customers table, it works fine but I've added another bindingadapter for the customercars table and when I add, it works fine but when I try to modify a record I get the following message:
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.
The update code is identical to the update code for the customers table and yet that updates fine. Any ideas guys? |
| Matt Deane Sunday, October 29, 2006 5:44 PM |
Hi It seems like I can't grab this book (I've registered the prod.). Is there a link? 
On the page there are just pics of books (in yellow or somethink). No downloads.
I'd appreciate if you were so kind to give me some more details. 
Thanks in advance!
|
| kdee Thursday, November 30, 2006 9:20 AM |
I am still confused. I understand about the database having two locations and that the property 'DO NOT COPY/ALWAYS COPY can be changed but my datanever gets back to the application database, whichever option is used.
I can see the data in the database residing in the bin\debug but I wany it to be permanently sent to the copy of the database in the application.
Do I need to add an SQL query to make this happen or what? Is there any code that copies the datatable from one location to the other.
Nobody else seems to be having the same problem .....are you?
Thanks for any help
Neil345 |
| Neil345 Wednesday, December 20, 2006 12:49 AM |
You don't have to have a copy of database in your project - just use the same one as always.
1. In Data sources tab click Add datasource
2. Select the type of DB and which files to import to the project. (test it just to see)
3. This will create a nice dataset which will be a copy of the originalDB files you select.
4. You can select names as you please.
5. When connecting to a database dont use "ok" use "no" when the message about including a copy of database pops-in.
6. You're done! Almost!!!
7. Also you willhave to mark your new dataset in Solution explorer as "Copy if newer" if you would want to update olddata with new one.
8. If you double click on a form with added table from Data sources (like Datagridview). You will get a code window for that form. Then choose the righ event for binding navigator(exactly when you want your dataset to be updated) like let's say:
Private Sub YourBindingSource_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles YourBindingSource.CurrentItemChanged
Me.YourBindingSource.EndEdit()
Me.yourTableAdapter.Update(Me.YourDataSet.YourTable)
End Sub
Or any other event wth Binding source.
9. Reply to this post if it helps you so I will know if I was any good in helping.
|
| kdee Wednesday, December 20, 2006 1:49 PM |
Thanks Kdee
I appreciate your efforts in explaining but my problem is slightly different to the method that you are proposing.
I am creating a new dataset with an empty table but I am not using another database as my datasource. I am using XML to fill my datagrid from an external XML file. This works ok and I end up with a populated datagrid.
My problem is that I cannot update my database with this data. I can seethe table correctlyin the temporary database residing in bin/debug but I cannot get the data permanently stored in the other 'copy' of the database. When I exit my application the data is wiped.
I can change the data and then save it in a new xml file but I want to permanently save it in the applications database table.
Thanks for your help, please come back
Neil345 |
| Neil345 Thursday, December 21, 2006 9:47 AM |
I believe my answer was correct after all.
It's a different case but... I believe ... the same problem. If you have created a copy of original DB which is generaly put in bin folder then ..you have to update the original DB MANUALY!!!!!! Copy the BIN DB to original DB.
Yes... at least as I understand it. I read some article about it, which ended my one and a half months headache.
The other solution is not to include original db to bin folder in this case you have to also set up all other things like I proposed in my last reply. Then the updated data from "project dataset" which is a "virtual mirror" of your original DB gets copied into the original DB and this automatically updates your original DB.
Many people have already asked about this problem with many headaches also ( almost everyone with more than several days of trying for themselves). See the past few months for articles in this forum and "VOILA" .... many people like you and me.
Maybe you will also find other solutions.
See ya!
|
| kdee Thursday, December 21, 2006 1:23 PM |
Thanks for coming back again Kdee but you have completely lost me.
Can we just do a rewind and go through itagain
I am not using a database as a datasource,but I have a datasetwith anempty table. I get my data from an XML file which is designed to fit nicely intothis empty tables datagrid on my form. I then pull in the data ok and press the 'save' button but the update does not get propagnated to the underlying database.The correctdoes however then reside in a temporary file in the bin/debug. (WHY?)
You say that I have to manually copy it to my underlying database (still empty at this stage)
I don't understand why I should have to manually copy it and I don't know how to do that either.
There is something wrong with my basic understanding of what happens. Why isn't the table adaptor doing its job? Is it because it knows that it didn't supply the data via a data source? Why should it care?
I think its a fault in Visual Studio
Regards
Neil345
|
| Neil345 Thursday, December 21, 2006 2:59 PM |
sorrry
Try to look further if anyone had the same problem as you. I believe I can not help you more. I hope you'll find the solution fast.
|
| kdee Thursday, December 21, 2006 3:10 PM |
I tried all sorts of thing but in the end what worked was this
Go to the Data Sources Sidebar
Right click on the DataSet and click Edit DataSet with Designer
Right click on the Database and click Configure
Click Advanced Options and tick Generic Insert, Update and Delete Statements
I also ticked Use optimistic concurrency although I dont't think that was needed
Hopefully this helps someone else out of a headache
|
| Grant McConville Sunday, February 04, 2007 9:05 AM |
So Helpful, so helpful. |
| MyNameIsSean Saturday, February 17, 2007 7:39 AM |
Thanks much....I lost hours on that one |
| WhatAboutBlob Tuesday, March 20, 2007 10:07 PM |
I had the same problem and that works, thanx. |
| Saturday Thursday, May 10, 2007 1:09 PM |
The Copy Always / Copy if Newer did the trick for me too. I was following the lessons in the Visual Studio Express Edititions learning center, but the lesson doesn't mention this option. I suppose that is because the lessons were created using a Beta version of Visual Studio Express. I'm very happy I've found the solution here, cause it was driving me crazy  |
| comecme Monday, August 06, 2007 9:49 PM |
1. go to your solution explorer 2. click your database.mdf icon 3. go to its properties 4. change the copy to output directory copy always to do not copy. 5. then go to the folder where you save your project copy the .mdf into debug which can be found in the bin folder
hope it helps
|
| Ma-aM Saturday, August 11, 2007 11:23 AM |
this thread is still working.
Have spent hours on this problem - and setting the property on the databse to "copy if newer" also worked for me.
GREAT.
thanks all.
|
| Gudmand Wednesday, September 12, 2007 5:13 PM |
You are my hero
I have spent a whole week trying to find out why this was happening with C#
I have tried several solutions in an effort to understand the architecture
I understand it now that you pointed out this annoyance
Thanks |
| Laser Dave Sunday, November 11, 2007 7:01 PM |
| kdee wrote: |
|
You don't have to have a copy of database in your project - just use the same one as always.
1. In Data sources tab click Add datasource
2. Select the type of DB and which files to import to the project. (test it just to see)
3. This will create a nice dataset which will be a copy of the originalDB files you select.
4. You can select names as you please.
5. When connecting to a database dont use "ok" use "no" when the message about including a copy of database pops-in.
6. You're done! Almost!!!
7. Also you willhave to mark your new dataset in Solution explorer as "Copy if newer" if you would want to update olddata with new one.
8. If you double click on a form with added table from Data sources (like Datagridview). You will get a code window for that form. Then choose the righ event for binding navigator(exactly when you want your dataset to be updated) like let's say:
Private Sub YourBindingSource_CurrentItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles YourBindingSource.CurrentItemChanged
Me.YourBindingSource.EndEdit()
Me.yourTableAdapter.Update(Me.YourDataSet.YourTable)
End Sub
Or any other event wth Binding source.
9. Reply to this post if it helps you so I will know if I was any good in helping.
| |
Hello, i've done the exact procedure. I've binded it to a datagridview, it worked! but the downside is I have to select another row inorder to complete the update. Do you know any work arounds with this? thanx a lot. |
| wizardboy Tuesday, April 01, 2008 11:54 AM |
Great solution!! This works pretty well |
| Rulas85 Monday, March 02, 2009 5:39 PM |
This is because when you made the initial connection to the database with the wizard, it asked if you wanted to make this database part of your project, and you answered yes. When you do that, it copies the database to your project's directory. Everytime you run the application, it copies that blank database to the debug folder and connects to it. You can add data to it, and it does save it. When you run the program again, it copies the blank database again to the debug folder and overwrites the one that yousaved the data. That is why the data is being lost.
It is best not to select that option to copy it to your project. That option is only good if you are deploying a project to people that don't have a copy of the database. When you publish the release itwith that option, it would copy it one time to the installed directory of the applicaiton. They would not loose their data each time unless they installed it again. |
| MAXIMUM_MIKE Thursday, September 10, 2009 2:58 PM |