Product Documentation

FairCom ADO.NET Driver - Developer's Guide

Previous Topic

Next Topic

Populating a DataSet

CtreeSqlDataReader objects provide stream-based access to result sets of database queries. While streaming access is fast and efficient, it is also read-only and forward-only. You can’t, for example, back up and re-read the previous record with a CtreeSqlDataReader object or change the results and update the changes back to the database. Set-based access on the other hand, captures an entire query in memory and supports backward and forward traversal through the result set. It also lets you edit the data obtained through database queries and propagate these changes back to the data source.

Set-based data access revolves around two classes, DataSet, which is the equivalent of an in-memory database and CtreeSqlDataAdapter, which serves as a bridge between DataSets and the data source.

The following .NET examples below show how to create a DataSet from a FairCom DB SQL database.

.NET VB Example

procedure DisplayNames

var

conString : String;

hConnection : CtreeSqlConnection;

hCommand : CtreeSqlCommand;

reader : CtreeSqlDataReader;

begin

conString := 'User=ADMIN;Password=ADMIN;Database=ctreeSQL';

hConnection := CtreeSqlConnection.Create(conString);

hCommand := CtreeSqlCommand(hConnection);

hConnection.Open();

hCommand.CommandText := 'select name from tab1';

reader := hCommand.ExecuteReader();

while reader.Read() do

Console.WriteLine(reader['name']);

reader.Close();

hConnection.Close();

end;

Sub DisplayNames()

Dim conString As String = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”

Dim hConnection As New CtreeSqlConnection(conString)

Dim hCommand As New CtreeSqlCommand(hConnection)

Dim adapter As CtreeSqlDataAdapter

Dim dset As New DataSet();

hConnection.Open()

hCommand.CommandText = “select * from tab1”

adapter = new CtreeSqlDataAdapter(hCommand)

adapter.Fill(dset);

hConnection.Close()

End Sub

.NET C# Example

void DisplayNames()

{

String conString = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”;

CtreeSqlConnection hConnection = new CtreeSqlConnection(conString);

CtreeSqlCommand hCommand = new CtreeSqlCommand(hConnection);

DataSet dset = new DataSet();

CtreeSqlDataAdapter adapter;

hConnection.Open();

hCommand.CommandText = “select name from tab1”;

adapter = new CtreeSqlDataAdapter(hCommand);

adapter.Fill(dset);

hConnection.Close();

}

.NET C++ Example

void CreateTable()

{

String* conString = S“User=ADMIN;Password=ADMIN;Database=ctreeSQL”;

CtreeSqlConnection* hConnection = new CtreeSqlConnection(conString);

CtreeSqlCommand* hCommand = new CtreeSqlCommand(hConnection);

DataSet* dset = new DataSet();

CtreeSqlDataAdapter* adapter;

hConnection->Open();

hCommand->CommandText = “select name from tab1”;

adapter = new CtreeSqlDataAdapter(hCommand);

adapter->Fill(dset);

hConnection->Close();

}

.NET Delphi Example

procedure DisplayNames

var

conString : String;

hConnection : CtreeSqlConnection;

hCommand : CtreeSqlCommand;

adapter : CtreeSqlDataAdapter;

dset : DataSet

begin

conString := 'User=ADMIN;Password=ADMIN;Database=ctreeSQL';

hConnection := CtreeSqlConnection.Create(conString);

hCommand := CtreeSqlCommand(hConnection);

hConnection.Open();

hCommand.CommandText := 'select * from tab1';

dset := DataSet.Create();

adapter := new CtreeSqlDataAdapter(hCommand);

adapter.Fill(dset);

hConnection.Close();

end;

TOCIndex