ComponentOne True DataControl 8.0
Tutorial 2 - Using True DataControl with a Database

In this tutorial, you will learn how to make a TData control the data source of data-bound controls, such as DataGrid and TextBox. You will also learn how to use the True DataControl property pages to perform the basic tasks of defining database connection and TData fields. You will be able to run the program and observe its run-time behavior.

  1. Start a new project.

  2. Place an ComponentOne True DataControl 8.0 (TData1) and a Microsoft DataGrid Control 8.0 OLEDB (DataGrid1) on the form (Form1) as shown in the illustration:


  3. Select TData1, and click the right mouse button over it to open the control's context menu. Select the TData Properties option. This will open the True DataControl property pages dialog, where you can view and edit the properties of TData1. The dialog looks like this:


    Note: As you will soon realize, in most cases there is no need to write Visual Basic code if you are building your application with True DataControl, which promotes codeless application development, because instead of writing code, you will specify properties and expressions in the True DataControl property pages.
  4. Establish a database connection for the TData control.

    If you are familiar with the standard ADO data control (Microsoft ADODC) included with Visual Basic 6.0, you will find much commonality between them when specifying a database connection. In True DataControl, this is done in the DataSource property page.

    Press the Build button on the DataSource property page. This will bring up the Data Link Properties dialog, with four tabs in it. Select the Provider tab to display the list of all available OLE DB providers installed on your system. Select the Microsoft Jet 3.51 OLE DB Provider and click the Connection tab. Here you can Select or enter a database name: select the C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB database file using the ellipsis button on the right side of the edit box. Press the Test connection button to make sure the database connection is specified correctly. Now press the OK button to close the Data Link Properties dialog. The following text now appears in the text box:

    Example Title
    Copy Code
    Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
    
    Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB
    

    The same text appears in the ConnectionString property of the TData1 control in the Visual Basic Properties window. You have specified the ConnectionString property, which defines the database connection for a TData control.

  5. Once you have selected a database, you also need to specify the exact source of your data within the database. This is called the RecordSource in True DataControl, and consists of two properties: CommandType and RecordSource. Select 2 – adCmdTable in the CommandType combo box, then select Customers in the Table or Stored Procedure Name combo box. The page now looks like this:


    You can see that the RecordSource property in the Visual Basic Properties window is now set to Customers. Press the Test button on the DataSource property page to make sure your database connection and RecordSource are correct. You should see the following message: Test RecordSource succeeded.

  6. Instead of using the DataSource property page controls, you can directly enter all necessary property settings in the Visual Basic Properties window. So far, we have specified the following settings: 

    Example Title
    Copy Code
    TData1.ConnectionString
    
    Provider=Microsoft.Jet.OLEDB.3.51;Persist Security
    
    Info=False;Data Source=C:\Program Files\ComponentOne Studio\Common\TDDEMO.MDB
    
    TData1.CommandType         2 - adCmdTable
    
    TData1.RecordSource        Customers
    
  7. Select the General property page, and check all the check boxes in the Buttons group there. We want all available buttons on the TData control visible for our tutorial example. Click the OK button. Set the Tooltips property of TData1 to True in the Visual Basic Properties window.

  8. Select the Fields property page. Since you have already defined the database connection and RecordSource, you will see all fields of the Customers table. In this example, we need to expose three fields: CustomerID, CompanyName, and City. To do this, one at a time select each of the other fields in the data source tree-view window, and clear the Visible check box for all of them. An empty check box means that the field is accessible to your TData control, but is not exposed to controls that are bound to it.


  9. To change the field order from that of the database table, drag and drop the field names. For example, press the left mouse button over the City field name. Without releasing the button, move your mouse to the CompanyName field position, then release the button. The City field is now visibly positioned before the CompanyName field.

  10. Close the property pages by clicking the OK button or by pressing Enter. This will save the changes you have just made for TData1. The changes are saved in the control and not to your hard disk. They will be saved to your hard disk, however, when you save the form. The Apply button saves changes without closing the property pages. Select the Cancel button to discard any changes. As with all other controls, moving between property pages implicitly applies changes.

  11. Set the DataSource property of DataGrid1 to TData1. This binds the DataGrid1 control to the TData1 control. TData1 becomes the data source for the grid. Set the grid’s AllowAddNew and AllowDelete properties to True.

Run the Program and Observe the Following:

Close the program. Congratulations, you have successfully completed Tutorial 2!

You will learn more about True DataControl's power in the following tutorials. This tutorial was intended to familiarize you with basic usage and to provide a glimpse of True Rapid Application Development.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback