Database Methods Windows Form

Connect MS Access Database to C# Windows Form Application (Select-Insert-Update-Delete)

Here in this article, I will show you how to connect a C# Windows Form Application with MS Access 2016 database.

Step 1:

Open MS Access, click on a Blank Desktop Database. Give the database name “dbSchool.accdb“. and then click Create.

Step 2: Now create a Table in database, You can name a table anything you want, here I named it “Student” . There are three columns in the table IDFirstName and LastName like the following,

 

Step 3: Now open Visual Studio, start a new Windows Form  Application and give any name you want.

Step 4: Now Drag and Drop database file from the Documents to the Project Directory folder.

 

Step 5:

Form Design

Step 6:

Set SelectionMode to FullRowSelect

and  ReadOnly to True

 

Step 7: Write a Namespace for connectivity as in the following code snippet.

Step 8: Define global variables.

Step 9: Create a method for get the list of students.

Step 10: Create source code for Insert Button

Step 11: Create source code for Delete Button

 

Step 12: Create source code for Update Button

Step 13: Create source code for datagridview_cellEnter event

Step 14: Create source code for Form_Load event

 

Finally, finished  the project.

Here are the all codes:

 

Output:

1 Comment

  • Hi!
    The inserting works only with the insert button? If i write somebody in the grid, he is not int the access file open with Access.
    If i insert sombody with insert button, he is in the table in the Access too. Why?

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.