Product Documentation

FairCom ADO.NET Driver - Developer's Guide

Previous Topic

Next Topic

Reading Data

ADO.NET provides a basic object to read data from a database. This object is the DataReader, or CtreeSqlDataReader in the particular case of our data provider. CtreeSqlDataReader is a fast forward-only and read-only representation of the data returned by a FairCom DB SQL query. A DataReader object is obtained by calling the ExecuteReader() method of the CtreeSqlCommand object, after setting the CommandText property of a CtreeSqlCommand object to the appropriate FairCom DB SQL query.

You should always call the Close() method when you have finished using the CtreeSqlDataReader object.

The examples below show how to use a DataReader with various .NET languages.

.NET VB Example

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 reader As CtreeSqlDataReader

hConnection.Open()

hCommand.CommandText = “select name from tab1”

reader = hCommand.ExecuteReader()

While reader.Read()

Console.WriteLine(reader[“name”])

End While

reader.Close()

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);

CtreeSqlDataReader reader;

hConnection.Open();

hCommand.CommandText = “select name from tab1”;

reader = hCommand.ExecuteReader();

while (reader.Read())

Console.WriteLine(reader[“name”]);

reader.Close();

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);

CtreeSqlDataReader* reader;

hConnection->Open();

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

reader = hCommand->ExecuteReader();

while (reader->Read())

Console::WriteLine(reader[“name”]);

reader->Close();

hConnection->Close();

}

.NET Delphi 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;

TOCIndex