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

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

100 thoughts on “Programming in Visual Basic .Net How to Connect Access Database to VB.Net

  1. Professor Suresh with the way you recite nothing is understood and it is unreliable, it is too quickly and incomprehensive.

  2. Essence of Argan oil is so amazing. It moisturizes my body and help reduce my find lines. Try to avail company’s promotion as well.

  3. Termine sus preocupaciones financieras

    Termine sus preocupaciones financieras ahora: Ofrecemos todo tipo de préstamos para nuevo préstamo años, Préstamo Personal, Bienes Raíces, plan de negocios, renovación, Infraestructuras, Hotel, Préstamo de Inversión

    ETC a baja tasa de interés del 3%. póngase en contacto con nosotros: [email protected]

    +33 756 961 591

    para más información

    Termine sus preocupaciones financieras

  4. Hello, i want a CF7 next to any product-service so the visitor can ask something for that. For that, i wish to have a field that is already prefilled with the current product's name (or maybe %postname% from url?). My links will be like "mysite.com/products/categories/category1/my-product-1" while the title will be My Product 1. Maybe it also could be nice to have a list field with all category items and the form selects the one that is similar to the current page. Any ideas?

  5. If we want VB.NET developers to be first class citizens in the ecosystem there needs to be a move from TableAdapter methods for working with any database. Even suggesting TableAdapter methods makes it hard to consider modern possibilities like DataAdapter, working from connection and command objects to Entity Framework Core (or EF6). Even when this video is with Visual Studio 2010 developers (using Visual Studio 2013 and higher .eg Visual Studio 2019) will still find this and consider TableAdapter methods valid, especially with the appearance of an easy solution to work with Microsoft Access, SQL-Server etc.

  6. Thank you for the conversation tonight. There is no audio on some of these. I see nothing good on this. the conversation was good but i don't see were anyone have it and say how good it is. Will call you back

  7. Thanks for refreshing my old memories. I made a video rental shop and GPS management application of VB.Net but couldn't continue programming later on.

  8. I have got a question anyone who can assist? I would like to know that if you are doing FOR LOOP inside DO WHILE IN VB.NET
    is it essential to have initial prompt instruction and Accept instruction outside the DO WHILE before you begin the DO WHILE?

  9. fiz 30 vezes e não deu certo, creio que esse jxl não seja compatível com a ultima versão do java, alguém poderia postar os códigos por favor, obrigado!

  10. The Conversational Forms is intriguing, but not sure it's something I need for my newish blog at this point. Lots of fun and powerful things to consider.

  11. After downloading theme visual studio, meen mean, fire fox to beta chrome blue I'm left with 3 minutes pin on excel Nd power point works with u-tube but not working flix. if you get my drift.

  12. Thank you so much for posting these helpful videos.
    It helps me a lot in learning .NET tutorial.
    I'm your fan now.

  13. I am having problems with the "save" button, particularly this statement…"Table1TableAdapter.Update(Your_DatabaseDataSet.Table1)". The software just points out an error and says that this statement is not "declared". Does anyone have any bright ideas ???

  14. very helpful thank you very much. im planning to make 3 types of database but i dont know how can i make a program on how to integrate them altogether in one program. could you help me? i know a few things in this since im new i want to learn.. thanks

  15. Love the hidden message of the date, give all a guess May 1843 at the exact start time of this video,,, of screw it, the mean pi of distance from earth to the moon on May 16th 1843 at the start of this video, why? and why is he listening to a loca rockl legend in South Carolina now since dead

  16. Huge thanks. Bizarrely, there used to be a setting on the P9's that allowed what you're talking about by default, but a new secondhand one I bought no longer has this option. Therefore your option seems to be the only solution on my current P9!

  17. Nice video i found this link https://www.youtube.com/watch?v=Jn1io7MknHI for windows application. I thought this will other to.

Leave a Reply

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

Back To Top