RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Using Typed DataSets

Typed DataSets provide certain advantages over standard DataSets. For one thing, they are derived from an XML hierarchy of the target database table. The XML file containing the DataSet description allows the system to provide extensive code-completion capabilities not available when using standard DataSets. Strong typing of DataSet methods, properties, and events allows compile-time type checking, and can provide a performance improvement in some applications.

To create a strongly typed DataSet

  1. From the Database Explorer, select the data source you want to use.
  2. Drag and drop the name of the database table you want to use onto your form. This displays a BdpConnection icon and a BdpDataAdapter icon in the Component Tray.
  3. Select the BdpDataAdapter.
  4. Click the Configure Data Adapter designer verb in the Designer Verb area beneath the Object Inspector. This displays the Data Adapter Configuration dialog.
  5. Modify the pre-filled SQL statement if you like.
  6. Click OK.
    Note: Do not create a DataSet by selecting the DataSet tab
    in the Configure Data Adapter dialog. That tab applies only to standard DataSets.
  7. Click the Generate Typed Dataset designer verb in the Designer Verb area beneath the Object Inspector. This displays the Generate Dataset dialog.
  8. Select the database table you want to use.
  9. Click OK. This creates an instance of the typed DataSet and displays an icon <DataSet Name>1 in the Component Tray. For example, if your DataSet is DataSet1, the new instance will be named dataSet11. You will also see that an XML .xsd file and a new program file appear in the Project Manager under your project.

To modify how columns appear

  1. After you have created a new typed DataSet, drop a DataGrid component onto your form.
  2. Set the DataSource property to point to the typed DataSet and the DataMember property to point to the target table.
  3. Click the (Collection) entry next to the TableStyles property. This displays the DataGridTableStyle Collection Editor.
  4. Click Add to add a new member to the members list.
  5. Click the drop down list next to the MappingName property.
  6. Click the (Collection) entry next to the GridColumnStyles property. This displays the DataGridColumnStyle Collection Editor.
  7. Click Add to add a new item to the members list.
    Note: By default the item is created as a Text Box Column. You can also expand the Add
    button and select the BoolColumn if you want a boolean.
  8. Click the MappingName property, select the column you want to display in your grid, then change any additional properties you want, including the header name that will appear as the column header in the runtime grid.
  9. Click OK twice.
    Note: When you build and run the application, only the columns that you explicitly defined by following the steps in this procedure appear.

To modify the structure of the dataset

  1. In the Project Manager, double-click the .xsd file that contains the XML definition of your dataset.
  2. Edit the XML file to reflect how you want the dataset to be structured. You can change data types, names, and anything else about the structure.
  3. If you have the program code file (<dataset>.cs or <dataset>.pas) open in the Code Editor, close it now.
  4. Choose ProjectCompile to recompile the .xsd file. If you re-open the program code file, you will see that the file contains the changes you made to the XML in the .xsd file.

To set the Namespace property for a dataset

  1. In the Project Manager, double-click the .xsd file that contains the XML definition of your dataset.
  2. Find the targetNamespace property.
  3. Change the following text to a relevant namespace:

http://www.changeme.now/DataSet1.xsd

  1. If you have the program code file (<dataset>.cs or <dataset>.pas) open in the Code Editor, close it now.
  2. Choose ProjectCompile to recompile the .xsd file. If you re-open the program code file, you will see that the InitClass() class now contains the new namespace.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!