Click here to Skip to main content
12,828,907 members (50,123 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

15.7K views
2 bookmarked
Posted 17 Mar 2014

Working with Visual Basic Database Connection

, 17 Mar 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Working with Visual Basic database connection

It is pretty fun to work with Visual Basic database programming. You can incorporate database contents in your application with the help of easy to use Wizard in Microsoft Visual Studio. By using the wizard, all the programming is done by the Visual Studio editor.

Before we begin to explore it, there are few terms to understand for creating Visual Basic database connection:

  • DataSet: A DataSet simply refers to the contents of a database table
  • View: View is simply the result of a stored query on database
  • BindingSource: A binding source provides easy access to data using the DataSource property. You can bind form controls to this object for further interaction with data sources (For example, a database)
  • TableAdapter: Table Adapters connect to a database table. It is interface for communication between an application and database. You can execute queries and update data in your database with it.

Let’s say we have an Access Database named Test_Database and we want to connect with it in a Visual Basic .NET application. The database contains a table Table1 containing three columns FirstName, Age and FavoriteColor fields.

https://www.codeproject.com/KB/database/745455/cbda9616-e2ae-4201-86eb-2eb61bd7d16f.Png

Follow the steps below to get started:

  1. Navigate to Data Sources tab. Click Add New Data Source.

    https://www.codeproject.com/KB/database/745455/ca9b9ccd-3299-41e5-a7ca-ba657725cd6f.Png

  2. Choose Database as a Data Source Type and Press Next.

    https://www.codeproject.com/KB/database/745455/9ba4fcde-62a5-4d6e-9e98-16e8e6dfd285.Png

  3. Choose DataSet as a Database Model and Press Next.
  4. Next step is to select a data connection to connect to the database. You should select New Connection. As we are going to connect to an Access Database, select Microsoft Access Database File as Data source. Continue with the Default data provider for this type of Data source.

    https://www.codeproject.com/KB/database/745455/fba6c75f-9e57-40b0-89c2-539db50b028d.Png

  5. A new dialog box will open asking for the connection parameters. Click Browse and select the Test_Database file. As we have not set any password for the database, leave user name and password Blank. Test the database connection. A confirmation message will appear if everything went right. If you encounter an error, repeat the above steps from the start. After successful connection, Press OK to close the dialog box.

    https://www.codeproject.com/KB/database/745455/7b7bc3a2-89c7-4921-b109-cf69d0e6ff90.Png

  6. You will notice that a new Data Connection is created and selected. Press Next to continue. Visual Studio may ask you to copy the database file to the current project. Select Yes to proceed.
  7. After successful connection, a list of database objects is retrieved and shown in the wizard. Select both the Tables and Views to be added to project. Press Finish.

Congratulations! A new DataSet is now available in your project. You have successfully established Visual Basic database connection.

https://www.codeproject.com/KB/database/745455/83ab77d0-43ab-4d93-80e0-1a1d9127ca21.Png

Now, you can access the table columns easily on your form. Just drag and drop FirstName and FavoriteColor onto the form. Press F5 to run the Test Application.

https://www.codeproject.com/KB/database/745455/27dafb22-c3c0-437d-b816-edf8a181128f.Png

Binding Navigator

  • Binding navigator provides with options for connecting and modifying the contents of database.
  • You can access the database records from quick navigation buttons (Previous/Next).
  • You can add or delete records from your database.
  • You can save the changes to database using the Save button. This ensures that the changes in DataSet are reflected to actual database stored in the Project output directory.

A video guide is presented for further illustration.

The post Working with Visual Basic database connection appeared first on Bubble Blog.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sharjeel_Ahmad
Engineer http://bubbleblog.net/
Pakistan Pakistan
A Telecom Engineer, Visual Basic enthusiast and Android news follower. He is contributing to an online blog as content writer and administrator
You can visit him here: http://bubbleblog.net/

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralDatasets are outdated Pin
Klaus Luedenscheidt17-Mar-14 20:54
memberKlaus Luedenscheidt17-Mar-14 20:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 17 Mar 2014
Article Copyright 2014 by Sharjeel_Ahmad
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid