How to Create a Data Source in Visual Studio.NET
Welcome, in this tutorial we are going to create a new data source in Visual Studio.Net using the built in wizards and drag-n-drop. To begin go to “File”, “New”, “Project” and name the project something like “MyPubsDataSource” or whatever makes sense to you. This will be a windows application although it’s not really important because we just need any type of project because creating a new data source is commom to all project types. Ok after you enter a name for your project and press the “Ok” button VS.Net will have created your first form for you named “Form1.cs”. At this point the form1 view should be already in design view(If you see a rectangular window that reads “Form1.cs[Design]* then you are in design view.
Ok next click once anywhere on the form and then select the “ToolBox” tab on the left of the design window. If it’s not viewable then select “View”, “ToolBox” from the main menu.(See image below).
Which will show you the window below.
Ok, next select the “SQLDataAdapter” from the ToolBox and drop it anywhere onto your form. Once you release it, it does not actually sit on top your form but instead it positions itself just below your form inside the design area. At this point you will have another window in front of you for you to choose your data source like this(See image below).
(click to enlarge)
On the next window choose Microsoft SQL Server or Microsoft SQL Server 2005 Express or whatever your data server may be. The next thing to do is enter your server name if you know what it is if not press the drop down arrow and select it from the list of providers.(See image below).
(click to enlarge)
Next, if your server is setup for it then you can choose “Windows Authentication” if not and you know what your SQL Server login settings are then enter the user name and password. Now you want to test your settings and make sure you can connect to your server so click on the “Test Connection” button now. Next you will get a message box showing the connection status of the test. If it’s ok press the “OK” button and the form will close and you will be back at the Data Adapter Configuration Wizard. Select either “Yes or No” to save the password for your connection in the App.config file. (Please note if you select “No” you will be prompted for it each time you run any of your applications that need to connect to SQL server for data). I normally select “Yes” as I setup a login on SQl Server with only enough rights to handle the data I’m working with.
Ok, now click “Next” to advance to the next screen of the wizard. Here you can use sql statements, use existing stored procedures, or create new stored procedures. For now select “Use SQL Statements” and press the “Next” button.(See image below).
(click to enlarge)
The next window you will see will be this one.
Select the “Sales” table and press the “Add” button and then the “Close” button.
The following window will appear below.
Select the (All Columns) square to place a tic mark and then press the “OK” button to save and close the window. You are once again back at the wizard and now you will see this code in the center.
Ok, great, now press the “Next” and then the “Finish” button. In design view of Form1 just below the bottom of the form right click on the “sqlDataAdapter” and select generate dataset. Just go with the default settings and press the “OK” button. Ok now right click on the “sqlDataAdapter” again but this time choose “Preview Data”. On the form that pops up(See image below) press the “Preview” button.
You will now see your data in the resulting form.(See image below).
Ok now just press the “Close button once you are thru looking at the data. Awesome, you have just created your first sqlDataAdapter, SQLConnection, and dataset. You could now use this new dataset in any .Net control of your choice. In the next tutorial we will do just that.
Thank you for taking the time to go thru this tutorial and I really hope that you have gained some knowledge from it. It is my full intention to make these tutorials as complete and easy as possible. Until next time take care and keep learning.