Connecting msAccess Database to Your C# Apps

Introduction

The ADO.NET object model provides an API for accessing database systems programmatically. Namespace System.Data is the root namespace for the ADO.NET API, the primary namespace for ADO.NET. System.Data.OleDb and System.Data.SqlClient contain classes that enable programmers to connect with and modify the data sources.
Some keywords:
  • DataSet: it stores the data in disconnected cache.
  • DataAdapter: the DataAdapter class represents a set of database commands and a database connection that you use to fill the DataSet and update the data source. It serves as a bridge between a DataSet and the data source.
  • Connection: it serves as a bridge between a data source and the application.
  • DataSource: is the database that the application will connect to.

Background

I’ve searched well so many sites about a code that I can [with the help of it] use ADO.NET to connect the Access database with a C# application. After searching the C# books, I’ve found some nice code that helped me to create this simple application. Hope it can help as a basic architecture.

Using the code

At first, you should simply open VS.NET and then at the File menu, click on New, Project. From the New Project dialog box, choose the Windows Application template project and name it WindowsApplication1, like shown below:
IE Window Class Names
After creating a window, add to it, four buttons Add, Update, Delete, Find, and four text boxes ISBN, Title, Author, Edition Number, and a label that represents the query that executed. The application will look like:
IE Window Class Names
Now, add OleDbDataAdapter in your application to control the database. The Access database that the application connects with will look like:
IE Window Class Names
When you add the OleDbDataAdapter, a configuration wizard will appear like:
IE Window Class Names
IE Window Class Names
Now, you should create a connection that will connect to your database. To do this, click on “New Connection” button.
IE Window Class Names
Select “Microsoft Jet 4.0 OLE DB Provider”. This provider enables the connection to communicate with the Access database. After that, click on “Next” button.
IE Window Class Names
In this page, you should determine the path of the data source that your application will connect with. After you do this, you can test the connection to ensure that there is no problem in the connection.
IE Window Class Names
IE Window Class Names
Finally, write the query that the data adapter will load in the DataSet; you can write the query manually or by the query builder.
But before that you should generate the database , to do this go into its property sheet and on the bottom of the sheet, select "Generate dataset".
IE Window Class Names
After finishing these steps, your application is now ready to control the database.
No comments

No comments :

Post a Comment