简体   繁体   中英

Connecting access database to a multiform project in C#

I have a multiform project I've created in C# and I need to connect my access database to it. My question is where do I add the connection code that will be used to update and delete items in my project? I have about 8 different forms but only 1 form really needs to access the database itself. Do I add the connection to Form1, the main form or does it need to be on the form that will be accessing the database?

It basically depends on what your requirements is, in general I would prefer to have a specific class handling and abstracting the connection to the database, or better a connection pool component inside the application .

If you want to put the connection object directly on the Form, I think that you should place on the form that needs the connection to the database, and in the future having different connection objects on each form that needs to connect to the database. You should avoid to have only one Connection instance shared to all applications forms/components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM