After establishing a connection to a FairCom DB SQL database, you can execute commands and return results from a data source using a CtreeSqlCommand object. The following steps are usually necessary to execute commands:
A CtreeSqlCommand object can be constructed with a default constructor with no arguments or using optional arguments of SQL language command text and/or a CtreeSqlConnection. The command text can be queried or modified using the CommandText property.
CtreeSqlCommand object exposes several Execute() methods that can be used to perform the intended SQL action:
Below are examples demonstrating command execution in various .NET implementations.
.NET VB Example
Sub CreateTable()
Dim conString As String = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”
Dim hConnection As New CtreeSqlConnection(conString)
Dim hCommand As New CtreeSqlCommand(hConnection)
hConnection.Open()
hCommand.CommandText = “create table tab1 (name char(20), age integer)”
hCommand.ExecuteNonQuery()
hConnection.Close()
End Sub
.NET C# Example
void CreateTable()
{
String conString = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”;
CtreeSqlConnection hConnection = new CtreeSqlConnection(conString);
CtreeSqlCommand hCommand = new CtreeSqlCommand(hConnection);
hConnection.Open();
hCommand.CommandText = “create table tab1 (name (char(20), age integer)”;
hCommand.ExecuteNonQuery();
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);
hConnection->Open();
hCommand->CommandText = “create table tab1 (name (char(20), age integer)”;
hCommand->ExecuteNonQuery();
hConnection->Close();
}
.NET Delphi Example
procedure CreateTable
var
conString : String;
hConnection : CtreeSqlConnection;
hCommand : CtreeSqlCommand;
begin
conString := 'User=ADMIN;Password=ADMIN;Database=ctreeSQL';
hConnection := CtreeSqlConnection.Create(conString);
hCommand := CtreeSqlCommand(hConnection);
hConnection.Open();
hCommand.CommandRText := 'create table tab1 (name (char(20), age integer)';
hCommand.ExecuteNonQuery();
hConnection.Close();
end;