Contents Index MobiLink .NET API Reference DBConnection interface

MobiLink Synchronization User's Guide
  Writing Synchronization Scripts in .NET
    MobiLink .NET API Reference

DBCommand interface


public interface DBCommand
Member of iAnywhere.MobiLink.Script

Represents a SQL statement or database command. DBCommand can represent an update or query.

For example, the following C# code uses the DBCommand interface to execute two queries:

DBCommand stmt = conn.CreateCommand();
stmt.CommandText = "select t1a1, t1a2 from table1 ";
DBRowReader rs = stmt.ExecuteReader();
printResultSet( rs );
rs.Close();
stmt.CommandText = "select t2a1 from table2 ";
rs = stmt.ExecuteReader();
printResultSet( rs );
rs.Close();
stmt.Close();

The following C# example uses DBCommand to execute an update with parameters:

DBCommand cstmt = conn.CreateCommand();
cstmt.CommandText = "call myProc( ?,?,? )";
cstmt.Prepare();
DBParameter param = new DBParameter();
param.DbType          = SQLType.SQL_CHAR;
param.Value           = "10000";
cstmt.Parameters.Add( param );
param                 = new DBParameter();
param.DbType          = SQLType.SQL_INTEGER;
param.Value           = 20000;
cstmt.Parameters.Add( param );
param                 = new DBParameter();
param.DbType          = SQLType.SQL_DECIMAL;
param.Precision       = 5;
param.Value           = new Decimal( 30000 );
cstmt.Parameters.Add( param );
// Execute update
DBRowReader rset = cstmt.ExecuteNonQuery();
cstmt.Close();
Prepare method 

public void Prepare( )

Prepare the SQL statement stored in CommandText for execution.

ExecuteNonQuery() method 

public int ExecuteNonQuery( )

Execute a non-query statement. Returns the number of rows in the database affected by the SQL statement.

ExecuteReader() method 

public DBRowReader ExecuteReader( )

Execute a query statement returning the result set. Returns a DBRowReader for retrieving results returned by the SQL statement.

Close() method 

public void Close( )

Close the current SQL statement or command.

CommandText property 

public string CommandText

The value is the SQL statement to be executed.

DBParameterCollection Parameters property 

public DBParameterCollection Parameters

Gets the iAnywhere.MobiLink.Script.DBParameterCollection for this DBCommand.


Contents Index MobiLink .NET API Reference DBConnection interface