Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器管理 » MobiLink 服务器 API » 使用 .NET 编写同步脚本 » 用于 .NET 参考的 MobiLink 服务器 API

 

DBCommand 接口

语法
interface DBCommand
Member of iAnywhere.MobiLink.Script
注释

代表一个 SQL 语句或数据库命令。DBCommand 可以代表一个更新或查询。

示例

例如,以下 C# 代码使用 DBCommand 接口执行两个查询:

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

以下 C# 示例使用 DBCommand 执行带有参数的更新:

public void prepare_for_download(
    DateTime last_download,
    String ml_username)
{
    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); 

    param               = new DBParameter();
    param.DbType        = SQLType.SQL_TIMESTAMP;
    param.Precision     = 19;
    param.Value         = last_download;
    cstmt.Parameters.Add(param); 

    // Execute update
    DBRowReader rset    = cstmt.ExecuteNonQuery();
    cstmt.Close();
}

Prepare 方法
ExecuteNonQuery 方法
ExecuteReader 方法
Close 方法
CommandText 属性
Parameters 属性