FunctionX Practical Learning Logo

Data Display on Sheet



Although you will create your databases as SQL files, to provide a friendlier environment, you will create forms and other graphical accessories that allow the users to access and view information. In Visual Studio, you would create a Windows application.

ADO.NET provides various ways to connect to a database, the simplest consists of using a SqlDataAdapter variable because this gives you direct access to the SQL Server database. With other techniques, or as traditionally done, you would have to create an ODBC Data Source. The Microsoft Visual Studio .NET programming environment is so close to SQL Server that you can create and manage a database as if you were using a single application to take care of this.

Practical LearningPractical Learning: Creating a Data Source

  1. Start Microsoft Visual Studio .Net and create a new Windows Forms Application named BCR1
  2. From the Server Explorer, expand the Servers node, the server that holds your SQL Server Installation, the SQL Servers node, and the name of the server you will be using
  3. Expand the BCR1 node and expand the Tables node
  4. Drag the CompanyAssets table and drop it on the form. You will receive a dialog box
  5. (Eventually, we will how to correct both warnings). Click OK


Introduction to Data Sets

The information stored in an object such as a database table is called a set, which is simply the group of its records. Because information is in fact referred to as data, the group of records in a table is also called a data set. To identify and manage the set of records, or data set, of a table, the Microsoft .NET Framework provides a class called DataSet.

After getting a connection to a database, you are ready to process it. You can use the data directly or, to better manage it, you can pass it to DataSet variable.

Practical LearningPractical Learning: Creating a Data Set

  1. Right- click the sqlDataAdapter1 icon in the lower section of the form and click Generate Dataset...
  2. Click the text box to the right of the New radio button and change it to dsCompAssets
  3. Click OK

The DataGrid Control

Data of a table is represented as a series of columns and rows. The columns are horizontal and hold the categories of information. A row contains entries various columns. The intersection of a column and a row is called a cell. The group of values stored in cells of a particular row is called a record.

To display information of a table, in the Server Explorer, you can just double-click it.

Instead of using a table to display data in cells, the Microsoft .NET Framework provides a control called DataGrid. This object also organizes its information in series of columns and rows whose intersections, called cells, hold the data of a table. To use a DataGrid, click it in the Toolbox and click the form. After doing this, you can specify that the information that displays in the cells will come from a DataSet. To do this, you can set the DataSource property of the DataGrid to the DataSet you have created. To actually display data in the DataGrid, you can call the Fill() method of the data adapter you are using.

Practical LearningPractical Learning: Display Data in a Data Grid

  1. On the Windows Forms section of the Toolbox, click DataGrid and click the form
  2. Position the DataGrid to the top-left corner and enlarge it
  3. Right-click the DataGrid and click Auto Format
  4. In the Formats list, click Colorful 3
  5. Click OK
  6. On the form, click the DataGrid to make it is selected. In the Properties windows, change the following properties:
    CaptionText: Company Assets Distributed to Employees
    DataSource: dsCompAssets1.CompanyAssets
    Anchor: Top, Bottom, Left, Right
  7. Double-click an unoccupied area of the form to generate its Load event
  8. Implement it as follows:
    private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
  9. Press Ctrl + F5 to execute the application and accept to save it:
  10. After viewing the form, close it

Home Copyright © 2004-2005 FunctionX, Inc.