Jump to content

Binding Access database to C# project

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
cowdog88

cowdog88

    Newbie

  • Members
  • Pip
  • 4 posts
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.

#2
kkelly

kkelly

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
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.