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

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

  1. Проект перспективный, обзор очень обширный и интересный! Спасибо!

  2. you know, I really do not post much in youtube comments. scratch that. I never do post in the youtube comments section. however, I had to sign in and say Thank you. out of all the youtube videos I have seen, you are the best. god bless you teacher. I have my exam tomorrow and this really helped me allot.

  3. You mention how the side characters don't get developed in the movie, and that is super true. But it is still better than how they are in the book. Aech turns out to be a woman of color and a lesbian (which isn't really addressed other than to show how cool a person Wade is because he doesn't care about any of that even though he promptly goes back to referring to Aech as a he in the OASIS because it's easier.), which feels like some sort of buffer to protect the author from the fact Daito and Shoto are the biggest Japanese stereotypes ever. The author even has both characters talk about how CEO Evilguy is dishonorable, in the same conversation, in almost the exact same line. Also everyone in the OASIS is described as a boring white person. And we have to read about Wade having an experience with a sex robot.

  4. Great information. We  need to protect those who are entrusted to us. We can use this same information to protect our elderly as well as those who are mentally challenged. We need to be their voice.

  5. Brandon, thanks for this tutorial; it  worked very well for a novice at this.  One question: I used the Syncios to transfer roughly 2,900 songs to my PC from my iphonr 7. Roughly 2,100 songs were duplicates that I planned to delete. But, when the process downloaded to my PC, it only shows 855 songs. Does that mean that the process automatically deleted duplicates? I sure hope so. Thanks again, Kwasi

  6. hi, new friend from saudi arabia, done watching your video and let support each other God Bless…

  7. Thank you for the video. I am international student and I did not have idea how to do this MLA format. It is definitely helpful.

  8. Проект выглядит очень привлекательным, присмотрюсь к нему

  9. Your videos are very informational when people are stuck with routine tasks

    could you please help me figure out this one, it's something most people at work come across nowadays which is a repetitive task of sending specific data of the week to a mailing list.
    I have an Excel sheet with loads of worksheets in it.
    Data is entered in 3 worksheets on daily basis and information from these 3 sheets is sent out to mailing list on every Sunday (data accumulated from Last Sunday to Saturday in those 3 work sheets).

    This XL sheet is stored in share point.

  10. Я долго занимался этим вопросом . Вы очень много для меня открыли познавательного . Продолжайте делать качественный контент

  11. To fast for a beginner like me with no audio explaining what's going on. It would be like me doing a engine replacement on your vehicle on video with no narration as there's details one needs to know on both items

  12. First of all thank you very much iBasskung for this amazing work ,this is exactly what i was looking for.I have a question i want to add a picture to a product so when i search for it i get all the information i need Name,Serial Number,actual location and the corresponding picture so users can see how the product looks like,how can i implement this ?

  13. You may know what you're doing but I understand shit. Why no sound? I watched a few minutes and gave up. But reading the comments you must be doing something right there just not for me.

  14. i am too depression drained to do this. is she going to steal my files? i can't fight her, help me!!! i don't know how to do this

Leave a Reply

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