Rowsets are the central objects that enable OLE DB components to expose and manipulate data in tabular form. A rowset object is a set of rows in which each row has columns of data.
With rowset you can open rowset with OpenTable and OpenQuery methods, move through data using MoveNext, MovePrev, MoveFirst, MoveLast, MoveToBookmark, MoveToRatio methods, get bookmarks using Bookmark property. But to access data you should use accessors.
Rowsets also provides columns information using ColumnInfo property. Item 0 of this list is always a self-bookmark column (if bookmarks are not available, data type will be DBTYPE_EMPTY).
In OLEDB Direct Components Suite rowset are implemented through TOLEDBRowset object.
To open rowset you should:
- Set DataSource property to an open data source object.
- Set properties you want to have in rowset. Some common properties can be set through TOLEDBRowset Flags property.
- (Optional) Set rowset navigator type you want to use. Rowset navigator differs by methods they calls in OLEDB interfaces to move through rowset. Standard and Bulk navigators uses IRowset::GetNextRows method, Locate uses IRowsetLocate::GetRowsAt method, Custom navigator is analogic to Locate but it stores every row bookmark and let use sort and filter without opening rowset with client cursor.
- Set TableName and IndexName or QueryText properties and call Open method. You can also use OpenTable or OpenQuery methods.
Example:
uses
OLEDBComponents;
var
rs: TOLEDBRowset;
i: Integer;
begin
rs.DataSource := ds; //Set valid TOLEDBDataSource object here.
rs.TableName := 'Orders';
rs.Flags := [rfBookmarks, rfLocate, rfScroll, rfCanScrollBackwards,
rfCanFetchBackwards, rfCanHoldRows, rfChange, rfDelete, rfInsert,
rfOwnInsert, rfOwnUpdateDelete];
rs.Open;
rs.MoveFirst;
while not rs.EOF do begin
//Do anything with rowset here.
end;
rs.Close;
end;