ComponentOne DataObjects for .NET
How to Access Table Data
DataObjects for .NET (Enterprise Edition) > Schema Objects > Simple Tables > How to Access Table Data

Data Binding

As described in Schema Objects, fetched data is contained in a C1DataSet object. By using a C1DataSet component as your data source, you can bind data-aware components such as a grid or a text box to the fetched data. The C1DataSet component exposes table view rowsets. Data-aware controls can bind to any of these rowsets. A table view represents a table, but there can be multiple table views representing the same table. Also, table views can represent composite tables as well as simple tables. C1DataSet also supports master-detail hierarchy in data binding. See How to Access Table View Data for details.

DataObjects for .NET also allows you to bind directly to a simple table rowset, bypassing table views. This can be done at run time by setting the DataSource property of a data bound control to a C1DataTable object representing a table rowset. To obtain this C1DataTable object, use the Tables collection property of the C1DataSet component.

This can also be done, both at run time and at design time, by using the C1DataView component. It can represent either a table view, if its TableViewName property is set, or a simple table, if its TableName property is set.

Programmatic Access

To access a table rowset (both for simple and composite tables), obtain a C1DataTable object from a C1DataSet component (using the Tables collection property), and use the Rows collection containing C1DataRow objects representing table rows. To perform actions on table rows or table data as a whole, use the appropriate methods and properties of the C1DataTable and C1DataRow classes. Their object model is similar to that of ADO.NET.

DataObjects for .NET also allows typed access to table and table view rows. For each table and table view, DataObjects for .NET generates a class representing its row. For example, ProductsRow is an object (business object, data object) where each field has a corresponding property (ProductsRow.UnitPrice, ProductsRow.UnitsInStock, and so on) and each relation has a corresponding method (Products.GetOrder_DetailsRows, and so on) allowing you to obtain child rows and the parent row. Using these classes, you can write your business logic code in a convenient, type-safe way, and benefit from Visual Studio code completion features giving you the lists of properties and methods to choose from. See Using Typed Data Objects in Business Logic, for details about these data object classes.

To use a data object class in your code, call the static Obj method implemented in every data object class. It obtains a business object given a C1DataRow object as its argument. For example, the following code obtains a ProductsRow business object from a C1DataRow:

To write code in Visual Basic

VB
Copy Code
Dim dataRow As C1.Data.C1DataRow
 
Dim product As DataLibrary.DataObjects.DataSet.ProductsRow
product = DataLibrary.DataObjecs.DataSet.ProductsRow.Obj(dataRow)

To write code in C#

C#
Copy Code
C1.Data.C1DataRow dataRow;
 
DataLibrary.DataObjects.DataSet.ProductsRow product;
product = DataLibrary.DataObjects.DataSet.ProductsRow.Obj(dataRow)

Sometimes it may be necessary to obtain C1DataRow objects from the rows (items) received by bound controls from DataObjects for .NET. For example, you may need to access the current row obtained from CurrencyManager.Current as a C1DataRow. Row objects (also called data items) used in data binding are not C1DataRow objects, but each of them refers to a single C1DataRow object, and you can use a static FromDataItem method to obtain that C1DataRow object.