Programming in Visual Basic .Net How to Connect Access Database to VB.Net

25M+ views   |   11K+ likes   |   2K+ dislikes   |  
Dec 12, 2013


Programming in Visual Basic .Net How to Connect Access Database to VB.Net
Programming in Visual Basic .Net How to Connect Access Database to VB.Net thumb Programming in Visual Basic .Net How to Connect Access Database to VB.Net thumb Programming in Visual Basic .Net How to Connect Access Database to VB.Net thumb


  • Hello to all Youtube audiences.
  • The first step is to create the new database.
  • Right click on an empty space. After that, select ‘New’. Then select ‘Microsoft Office Access 2007 Database’.
  • We have to name our database. For example, it’ll be named Your_Database which the file extension is .accdb
  • After that, hit ‘Enter’ on the keyboard or double click on the file. ‘Access’ program will automatically open.
  • Then we will create a new table to collect data. Go to ‘Create’ tab and choose ‘Table’.
  • Right click and choose ‘Design View’. The program will let us name the table. I will name it ‘Table1’.
  • Add a new field. You can follow my lead.
  • ‘YourName’ field, in this case I mean ‘First Name’. The data type is Text.
  • ‘LastName’ field is for keeping last names. It has same data type with ‘YourName’.
  • ‘Phone’ field is for keeping phone numbers. The data type is also Text because we don’t mathematical calculate it.
  • ‘Email’ is for keeping email addresses. The data type is Text.
  • ‘Facebook’ field is for keeping Facebook accounts. (This one is optional).
  • After that, right click on the table header and hit the ‘Save’ button to save. Then, choose ‘Datasheet View’ to view the data. It will look similar to the program ‘Excel’.
  • For now, close the program ‘Access’ then open ‘Visual Studio. We will create a new project.
  • Click ‘New project…’ in ‘Start Page’ or go to ‘File’ menu and choose ‘New --> Project…’.
  • Choose ‘Visual Basic --> Windows’ then choose ‘Windows Forms Application’ in order on the right tab.
  • Now, name our project. I’ll use the one that the program named which is ‘WindowsApplication1’.
  • We will find an empty form name ‘Form1’ which is automatically created by the program. Click ‘Save’.
  • Click ‘Toolbox’ on the right tab and then choose ‘Dock’ to always show this window.
  • Here, we can satisfactorily adjust the form size.
  • I will add ‘TextBox’ and ‘Label’ control by dragging it from ‘ToolBox’ window to our form.
  • Then reposition it wherever you want.
  • I will add a Button into the form. For User to use commands such as save or delete by clicking it.
  • We can browse qualities of the controls by right clicking on the specific control and choose ‘Properties’.
  • The ‘Property’ window will be showed on the right.
  • I will hide the ‘ToolBox’ window by choosing ‘Auto Hide’ to provide more using space.
  • Then, change the text on ‘Label’ control to be meaningful by adjusting in ‘Property Text’.
  • I will change the text to ‘Name:’ or ‘First Name:’.
  • Copy more ‘Label’ & ‘TextBox’ controls until it completed the number in the field we created in the data base.
  • You can follow my lead.
  • Then, change the text in every ‘Label’ control to be meaningful and appropriate.
  • The second one will change to ‘LastName’.
  • The third one will be ‘Phone’.
  • The fourth one will be ‘Email’.
  • The fifth one which is the last one, will be changed to ‘Facebook’.
  • Do the same thing on Control Button.
  • The first button, I will change the text to ‘Previous’.
  • Copy all the buttons as you wanted. In this case, please follow my lead.
  • After that, change all the text in every button.
  • Change the text to ‘Add New’ on the second button.
  • Change the text to ‘Next’ on the third button.
  • Change the text to ‘Save’ on the fourth button.
  • Change the text to ‘Delete’ on the fifth button.
  • Change the text to ‘Close’ for closing the present form on the sixth button which is the last one.
  • In case there is an only form, the program will be closed.
  • Next, adjust the size of every ‘TextBox’ controls as you wanted.
  • Then, I will hide the ‘Properties’ window for now and I will open ‘ToolBox’ window instead.
  • Add 2 ‘GroupBox’ controls to the form for categorizing controls in the form to nice and tidy.
  • Adjust the form to an appropriated size.
  • We will find that the ‘GroupBox1’ is covering other controls. Right click and choose ‘Send to Back’.
  • Arrange the position and adjust the size of the controls on the form. Here, you can follow my lead.
  • Next, I will add ‘DataGridView control’ into the form. This control is used to show data from the database.
  • Click and drag it to ‘GroupBox2’ control.
  • Hide the ‘ToolBox’ window for now.
  • Adjust the size of ‘DataGridView’ as you wanted.
  • If the form is too small, we can adjust the size into any sizes we want.
  • It might take some times. You can follow my lead.
  • After you are satisfied with the adjustment, click ‘Save’ to save.
  • The next step is to add a data source by choosing from the Access database into our project.
  • Go to ‘Data Sources’ window on the left, choose ‘Add New Data Source’ button.
  • ‘Data Source Configuration Wizard’ window will be appeared like this.
  • Choose ‘Dataset’ then choose ‘Next’ and ‘Next’ again.
  • Click ‘New Connection…’ button then choose ‘Browse’ to choose a database file the we created.
  • Click ‘Test Connection’ button to test the database connection.
  • Click ‘Next’ then ‘No’ because we will manually copy the database file into the project.
  • Click ‘Next’ again then check (check mark) all of it. Click ‘Finish’.
  • Next, I will add data source to the ‘DataGridView’ control.
  • Click the triangle button on the right corner then choose ‘Data Source’ which is ‘Table1’ in this case.
  • Click the check mark before ‘Enable Column Reordering’.
  • We will find that the table header text will appear on ‘DataGridView’ which we can use the data from the table we created.
  • Here, we can adjust the size of form and controls as you wanted. You can follow my lead.
  • Next, I will hide the column ‘ID’ from User sight because this field is AutoNumber.
  • Change it from ‘True’ to ‘False’ at ‘Visible’ then click OK.
  • We will find that ‘ID’ column is gone (hidden).
  • If the window is too small, we can adjust the form size for a nice appearance. It might take some time.
  • Next step,
  • I will create ‘Data Bindings’ or binding the data from the field in the data source to every ‘TextBox’ control.
  • Right click on the first ‘TextBox’ then click ‘Properties’. Look for ‘DataBindings’.
  • At ‘Text’, choose ‘Field’ from ‘Table1BindingSource’ that will be bound with the first ‘TextBox’.
  • In this case, it is ‘YourName’ field.
  • (Please choose the correct one).
  • Do it to every ‘TextBox’. Follow my example.
  • Next is ‘LastName’. Do the same step which is selecting the correct data field.
  • Next, Do the same with ‘Phone’, ‘Email’ then ‘Facebook’.
  • Recheck that we correctly did ‘Data Bindings’ to every ‘TextBox’.
  • After we finish, click ‘Save’ button to save.
  • Then, we will write command code for the buttons.
  • Start with the ‘Previous’ button.
  • Double click on the button, there will be ‘Event Handler’ command code for automatic mouse clicking.
  • First command is to move the record 1 row previous. Please follow my lead.
  • Next, ‘Add New’ button for adding new data.
  • You can see that the commands are quite similar, just a little adjustment.
  • Next, ‘Next’ button for moving the record to the next one.
  • Next, ‘Save’ button for saving data to the data base. This command is little longer than others.
  • We will use TableAdapter to help in adding and updating
  • data that we changed in the Dataset to be saved in ‘Table1’ table in Access database.
  • Normally, we should write a command code for finding errors in the program.
  • Use the command ‘On Error Goto’. It means what will the program do after an error happens.
  • Mostly, it will show error messages then quit working.
  • In this case, if there are any errors while saving data, the program will jump to ‘SaveErr’ command that we created.
  • You can see that there is a : (Colon) after the command name. In the example, it is SaveErr:
  • In this case, if there are any errors, I will let it quit working by the ‘Exit Sub’ command.
  • In case the saving is flawless, it will show that the saving is complete by using ‘MessageBox.Show()’ command.
  • You can follow my lead.
  • Please always save the data while working.
  • Next, ‘Delete’ button for deleting a data row. The command is quite the same.
  • In this case is ‘RemoveCurrent()’.
  • The last button, ‘Close’ button is for closing the form. If there is only one form, it will quite the program.
  • Short command, ‘Me.Close()’.
  • Click ‘Save’ button after finish.
  • Check everything. Adjust the form as you wanted.
  • After that, we will test the program.
  • Click the green button (Start Debugging) or click ‘F5’ button on the keyboard.
  • We will see the form shows like this.
  • When you need to add data, click ‘Add New’ first. If you accidently click it for several times,
  • there will be rows added according to the numbers of the click. Click ‘Delete’ button to delete the rows.
  • After that, test typing details to every ‘TextBox’. You can follow the example in the video.
  • In this part, I will use hypothetical data, not real data.
  • After we finish typing, click ‘Save’ button to save data every time.
  • We will see that if there aren’t any errors, program will show the text that we inserted.
  • If we want to add new data, we have to click ‘Add New’ button every time like before.
  • Then, type details the every ‘TextBox’ as you wanted.
  • Click ‘Save’ button after finish every time.
  • I will add more data to use as an example. Here, we can test the running by ourselves.
  • This part, underline that we have to click ‘Save’ button after typing or adjusting any data.
  • If not, the data will not be saved.
  • If there are enough data, test the navigation buttons (Previous – Next) to see...
  • if it can correctly move previous or following records.
  • Test clicking ‘Close’ button to close the form and quit the program. You will see that the program stops working.
  • We will see that the data we added appears in every ‘DataGridView’ and ‘TextBox’.
  • Go in our Access database to see our real data first.
  • We will find that there is the data we added is already here.
  • OK. Close ‘Access’ program and the opened form for now. We will start testing the program again.
  • I will add more data for the test. You can add whatever data you want.
  • After that, click ‘Save’ to save every time.
  • Click ‘Close’ to close the program. Then go check the data in database again.
  • You will find that the new data has been added.
  • Adjust the back color of the both ‘GroupBox’ for a nice appearance. You can follow my lead.
  • Click ‘Save’ and click ‘Start Debugging’ to run the test again.
  • Choose a row that you want to adjust.
  • When finish adjusting, click ‘Save’ button to save data every time.
  • *** If you want to delete, choose the row you want from ‘DataGridView’ then click ‘Delete’ button. After that, click ‘Save’ button to save data every time.***

Download subtitle


Tutorials & Source Code: Visual Studio 2010 | Visual Basic .NET and Access Database.

English Closed Captions / Subtitles are Now Available

Source Code: Programming in Visual Basic .Net How to Connect Access Database to VB.NET
➜ http://bit.ly/30NcRKc

Here are all related to this video:
➜ (YouTube Playlist): http://bit.ly/2OsJJko

NEW UPDATE: Visual Studio 2019 (VB.NET 2019) | How to Connect to Data in an Access 2016 Database.
(Part 1/3) /watch?v=t68bCOPUzyM
(Part 2/3) /watch?v=o3YxbM4Lcwo
(Part 3/3) /watch?v=6UqEgH8mFi8

See also
‍ Visual Studio 2019 | Visual Basic .NET (VB.NET 2019) Searching Data in an Access Database.
(Part 1/3) /watch?v=_gW8EIrdJ9g
(Part 2/3) /watch?v=WRuprNKbcyg
(Part 3/3) /watch?v=RKYReKRJuz4

Recommended videos:
4K ULTRA HD 3 in 1 Tutorial: How to Download and Install Visual Studio Community 2019, SQL Server 2017 Express Edition and SQL Server Management Studio (SSMS).

‍ How to make an inventory database in MS Access 2013 - 2016.
Inventory Management System | Stock Management Database.

// ** //


I CAN'T BELIEVE WE'VE HIT 20 MILLION VIEWS ON THIS VIDEO: "Programming in Visual Basic .Net (VB.Net) How to Connect Access Database to VB.Net".

Thank you for all the likes, comments and subscribes and making this dream a reality!

⚡ See the 20 million views freedom video:
➜ /watch?v=cwDqjmSmtMQ

For C# version, please check out this playlist:
➜ Visual C# .NET and Access Database (C# Premium Tutorials) : Workshop for Complete Beginners.
➜ http://bit.ly/2Q8w0Vx

Please subscribe for more videos: ➜ http://bit.ly/2zAg8Ag

// * * //

If you would like the source code and project file. Please donate me via PayPal.

Please contact me: ibasskung@gmail.com

// * * //

‍ Online Programming Courses ‍
Visual Basic .Net, Access Database, EAN-13 Barcode Generator, and Crystal Reports using a Project-Based Approach. "The Point Of Sale (POS) System".

Enroll Now. You can get started on your first lesson right away

Promo videos:
(English): /watch?v=GX6TOCBqsGk
(Thai): /watch?v=NRSvx6L4co0

Note: English Version Coming Soon!

// * * //

⛳ Follow me around ⛳
✔ Want to get updates on new courses or other cool free stuff? Just follow me on social media if that's your thing!



Udemy (Online Course):




// ** //

English Tags:
visual basic
visual basic access
access database
visual basic database
how to connect database to vb.net
how to connect access database to visual studio 2010
how to connect database to visual basic 2010
how to connect microsoft access database to visual basic 2010
programming in visual basic .net how to connect access database to vb.net
database connectivity in vb.net
vb.net login using access database
vb.net login form using access database
login form in vb.net with database access
visual studio access database
vb.net connect to database
vb.net connect to access database

Thai Keywords:
เรียน เขียน โปรแกรม
สอน เขียน โปรแกรม
เขียน โปรแกรม vb.net
สอน เขียน โปรแกรม ออนไลน์
เขียน โปรแกรม