Is it possible to bind an access database to my project without hard coding? I just want to be able to update and save data. I can see my fields when I connect to the database, but I was hoping I would be able to just drop them on the designer.
Binding Access database to C# project
Started by cowdog88, Sep 12 2007 04:54 PM
1 reply to this topic
#1
Posted 12 September 2007 - 04:54 PM
|
|
|
#2
Posted 17 September 2007 - 12:12 PM
If you drag a table or query to the .NET IDE it will create a data adapter class for you. These work in a disconnected state. They do so by saving changes in a dataset class. You can generate the dataset class by right clicking on a dataadapter and selecting "Generate DataSet". If you have data adapters you can check the ones you want in the dataset. Once it is generated you can further modify it, like adding relationships. Now if go to the data bindings section in the properties of a control, you can bind things to your dataset. If you throw a data grid on your form, you could bind to a whole table or dataset.
You will have to write a tiny bit of code. When your form loads you will have to tell it to fill the dataset like: dataadapter.fill(dataset);
Then, when you want to save your changes back to the database, I believe you call dataset.savechanges() then dataset.acceptchanges(). It's been a little while since I've used those controls, but I think that is correct.
You will have to write a tiny bit of code. When your form loads you will have to tell it to fill the dataset like: dataadapter.fill(dataset);
Then, when you want to save your changes back to the database, I believe you call dataset.savechanges() then dataset.acceptchanges(). It's been a little while since I've used those controls, but I think that is correct.


Sign In
Create Account

Back to top









