ComponentOne DataObjects for .NET
Connecting to Database and Working with Data
DataObjects for .NET Express Edition > C1ExpressTable: Working with Simple and Composite Tables > Connecting to Database and Working with Data

You can connect to a database and begin setting properties for your table.

  1. Connect to a database:
  2. After connecting to a database, set the DbTableName property choosing a database table from a combo box or creating Composite Tables.
    It is recommended to use the DbTableName property to bind a C1ExpressTable to a database table, but you can also use the SelectCommandText property to specify a SQL statement or a stored procedure (the latter if the SelectCommandType property is set to StoredProcedure). Using SelectCommandText is almost as simple as using DbTableName, but you also need to create a DataAdapter component for this C1ExpressTable if you need it to be modifiable, have update functionality (select Create DataAdapter from the context menu).
    Also, SQL-based C1ExpressTable components (those that use SelectCommandText instead of DbTableName) cannot be used in composite tables and in virtual mode, and their FillFilter property is ignored.
  3. The last step is defining fields using the Fields Editor that opens when you press the button for the Fields property. For simple tables, DataObjects for .NET Express retrieves the fields collection from the database table. For a composite table, you must add fields from underlying database tables to your composite table using the Fields Editor. You can customize the Fields collection deleting and rearranging the fields, adding calculated fields and setting various field properties.

Once a C1ExpressTable component is bound to a database table(s), it can be used as a data source in data-aware GUI controls. Just select the component in the DataSource property combo box of a data-aware control. Note, that if you need master-detail data binding, you must use a C1ExpressConnection component as your DataSource and select appropriate DataMember values. The string representing a DataObjects for .NET Express table in DataMember is determined by the TableName property.

The FillOnRequest property (belonging to a C1ExpressConnection component) determines whether C1ExpressTable components are filled with data automatically at start-up (when data-bound controls request data from it). Setting FillOnRequest to False, you can fill them with data later, programmatically, calling the Fill method (C1ExpressTable.C1ExpressConnection.Fill).

Unless you specify a filter condition in the FillFilter property, C1ExpressTable will fetch all existing table data unrestricted. To restrict fetch, specify a SQL filter condition in the FillFilter property. In this condition, use field names in brackets, for example,


C1ExpressTable1.FillFilter = "[CategoryID] = 1"

Setting the FillSort property you can specify the order of fetched rows, for example,


C1ExpressTable1.FillSort = "OrderID,CustomerID"

By default, rows are sorted by primary key.

By default, DataObjects for .NET Express works in disconnected mode, just like standard ADO.NET: data is pre-fetched from the database in its entirety. In this mode, you cannot bring large datasets, with hundreds of thousands of records and more, to the client. However, DataObjects for .NET Express also supports so called virtual mode, where data size is unlimited. With its innovative virtual mode technology, DataObjects for .NET (both editions) allows you to use large datasets, unlimited in size, in .NET WinForms applications. This feature is not supported in Visual Studio .NET and ADO.NET without DataObjects for .NET. See Tutorial 4: Virtual Mode: Dealing with Large Datasetsfor an example of a rowset containing 2.7 million rows that is available on the client with limited memory consumption and startup time of about three seconds. See Tutorial 4: Virtual Mode: Dealing with Large Datasets in DataObjects for .NET documentation for details on virtual mode. In DataObjects for .NET Express, virtual mode is enabled by setting the DataAccessMode property of a C1ExpressTable component.

The AllowAddNew, AllowDelete, and ReadOnly properties determine whether the user can modify table data. By default, user modifications are cached on the client and not sent back to the database. The database is updated, modifications written to the database, when the Update method is called from code. DataObjects for .NET Express also supports an automatic update mode. In this mode, a modified row is automatically updated to the database when the end user leaves that row, when another row becomes current. To enable automatic update mode, set the UpdateLeavingRow property to True.

See Also