![]() |
Database Visual Support: A Data Source |
|
Introduction |
|
So far, we have introduced and used to primary tools that Microsoft SQL Server provides to create a database. We hardly did anything visually. To make database development user friendly and graphically-driven, Microsoft Visual Studio provides its own set of tools. Some of these tools are available from the Toolbox. Some other tools are provided as classes you can use as long as you are aware of them. We defined a data set as a system of values. The values are kept in one or more lists. We also saw that, to support this system, the .NET Framework provides a class named DataSet. This class is represented in the Data section of the Toolbox of Microsoft Visual Studio by the object of the same name. |
Instead of using the DataSet object from the Toolbox, Microsoft Visual Studio provides a technique that allows you to automatically get a data set object by creating a connection to a database. The data set would be filled with the tables from the database. To use it, you can first display the Data Source window. To display the Data Source, on the main menu, you can click Data -> Show Data Sources. To create a data source:
The first page of the Data Source Configuration allows you to specify the type of data source you want to create: Database, Web Service, and Object
If you click Database and click Next, the second page of the wizard allows you to select an existing connection or create a new one. To select an existing connection, you can click the arrow of the combo box and select from the list:
If you want to use, and select, an existing connection, you can click Next. If you click the New Connection button, you would then have to select the server, the authentication, and the database. In the third page of the wizard, you would specify a name for the connection string, and click Next. In the fourth page of the wizard, you have the option of selecting one or more tables (and others) to include in your data set. To do this, you can click the check boxes in the list. If you do not specify the tables, you can click Finish and, later on, you can reconfigure the data source and select the tables (and/or others). After making your selection, you can click Finish.
When you click the Finish button of the Data Source Configuration Wizard, Microsoft Visual Studio generates many classes (XML Schemas) and creates a data set object specially made and configured for your database. Practically, the studio would create a class named after the name you gave to the data set and this class would be derived from the DataSet class. To examine this created class, from the Solution Explorer, you can open the file that holds the name of the data set followed by .Designer.cs. Among the objects created in the data set class is a class that represents the table (or each table) you selected in the last page of the wizard. This class for the table is derived from the DataTable class and implements the System.Collections.IEnumerable interface. In order to use this new table in your code, you must declare a variable for it. Once you have done that, you can access the characteristics (properties, methods) of the table or its parent. Although the data set created from the Toolbox and the one generated from creating a data source have many differences, they still share the common definition of being data sets. As mentioned earlier, a data set created from adding a data source contains the table(s) (including its (their) column(s) and record(s), if any) you would have selected. This allows you to access any of the characteristics we studied for a data set. |
Published on Friday 04 January 2008
|
|
||
| Home | Copyright © 2007 FunctionX, Inc. | Next |
|
|
||