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

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.***


  1. на середине ролика ток заметил, что это не сишарп, а так полезное видео

  2. I like your video very much. It's really great. I'll keep an eye on your channel. I am your fan and I will support you.

  3. t worked! I thought I was going to install Linux to acces darkweb and thanks to you I dont need to do that. Youre a crack.Thank you very much,friend

  4. Ik zie het programma er niet tussen staan helaas.. ik moet een code intoetsen maar hoe moet ik dat doen? tool for reading MSI files

  5. I am loving the new learning track which makes it easier to see the path one should take to becoming an expert at Nativescript. I am a self taught though but strongly considering solidifying that through your courses.

  6. Dear sir,
    we have respect and we have have cannot work because your specific office is not Bangladesh of this alone which is not media that do communication from Bangladesh . Such search give arrive many bijoy kumar sarker then what all bijoy fund owner . we have request kindly also do not hollo my with .
    thank you for regards
    your faithfully
    bijoy kumar sarker
    Nabajug Unnayan Sangstha
    thakurgaon Bangladesh.

  7. pak saya mau tanya
    kalau kita membuat web app untuk bisa memonitoring data upload foto sebaiknya menggunakan apa?? mohon bantuannya

  8. I followed the video and made just same as He did. It works well most of case. However, Showing Error on Debug Text 'System.Data.DBConcurrencyException'(System.Data.dll) while clicking save button after several clicking Add new button and Delete button. I don't know how it occurs exactly, but I want to fix it. Is there anyone who can help?

  9. Hi! Thank you for the video. I got stuck around minute 6 where you tried to connect your Access file to VB. I keep having this window popup: "The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine." Can I get some help? Thank you!

  10. Hi help me can I open Visual Basic Studio via Visual Basic 6 where I have a program and I want to open it in Visual Basic 6

  11. Please help with the Visual Basic Studio 2010 project and I want to open it in Visual Basic 6 and does not want to

    Thank you

  12. My web connection for access database is not working on Windows server 2016, any idea what will be the issue? The application is working perfectly in Windows server 2008

  13. Well done iBass , the real force in your work is to push me in other direction to find different solution for every job's problem

  14. I create database connection access not with code give me some codes for refresh button to update after add data to data grid view please reply me any one

  15. hi your this video is not audible – . plz plz make this audible. your videos are really helpful

  16. very helpful thank you very much.but i have one problem …when i close the program ..all the data that i have been added ..was lost ..the data weren't saved in the access file .please i need help

  17. hi. why when i click on delete button the record get deleted but when i close and reopen the record is still there. Please help me with the delete function.

  18. hi sir , when i make setup for project include connect between database access and data grid view 2010 and when install on another computer .display massage that cannot know the path of database can you make video to explain this problem  ….thanks with best regard

Leave a Reply

Your email address will not be published. Required fields are marked *