When using the example in the previous post, or in other ocasions, you may see three items, the "DataSet", "BindingSource" and "TableAdapter", so here's what they do:
DataSet:
Stores data in memory when in "run time"
BindingSource:
Has all the information regarding the connection and is responsible for the navigation as all the other records functionality.
TableAdapter:
Gets data from the table and sends it to the application
Monday, June 18, 2012
Simple Database Connection
Connecting to a database is a process that can be very simple, depending on the need.
In this tutorial, i'll show you how to connect to a SQL Server database.
1) First Create a new Project

Name your project and choose the desired location on your hard drive, and press "OK"
8) Select "Dataset" and click "Next"
In this tutorial, i'll show you how to connect to a SQL Server database.
1) First Create a new Project

Name your project and choose the desired location on your hard drive, and press "OK"
immediately Visual Studio will create the solution for you;
2) Now, resize the form that will be holding the data, at your likes;
3) Drag and drop the "DataGridView" control into the form and resize it
4) Next, Select the "DataGridView" and click on the triangle on the top right of the control.
5) Select the combobox "Select Data Source"
6) Select the option "Add Project Data Source"
7) Select "Database" and click "Next"
8) Select "Dataset" and click "Next"
9) In this step "Choose your data connection", click on "New Connection"
10) A new window will be shown named "Choose Data Source"
11) Choose "Microsoft SQL Server". In here, if you don't have an SQL Server instance, then you can choose another database type.
Press "Continue"
12) You'll be presented with a window called "Add Connection"
- In this window, choose the "Server Name", by writting it or by choosing it from the combobox availlable items.
- Choose how you'll logon to the server. If you haven't configured your server to use passwords, use the first option "Use Windows Authentication", if not, you must supply the exact credentials in the second option.
-Select the database to which you want to connect to.
- Click on "Test Connection", and if your connection succeded, press "OK"
13) When returning to the window "Choose Your Data Connection", choose "Yes, include sensitive data in the connection string". and press "Next"
14) In the next section press "Next" to save the connection
15) In "Choose Your Database Objects", select the exact table you want to use or all the items and click "Finish" (when selecting all the items, like shown bellow, the wizzard will prompt you for the exact table to use, at the end of this process)
Now, you can just Press "F5" and run the project. If everything worked fine, you'll see you data listed on the form.
Subscribe to:
Posts (Atom)







