DB2 10.5 for Linux, UNIX, and Windows

DB2DataAdapter.SelectCommand 属性

获取或设置用来选择数据库中的记录的 SQL 语句或存储过程。

名称空间:
IBM.Data.DB2
组合件:
IBM.Data.DB2(在 IBM.Data.DB2.dll 中)

语法

[Visual Basic]
Public Property SelectCommand As DB2Command

[C#]
public new DB2Command
 SelectCommand {get; set;}
[C++]
public: __property DB2Command
* get_SelectCommand();
public: __property void set_SelectCommand(DB2Command
*);
[JScript]
public function get SelectCommand() : DB2Command
;
public function set SelectCommand(DB2Command
);

属性值

在填充操作期间用来从数据库中选择记录以便放置在 DataSet 中的 DB2®Command

注释

SelectCommand 指定给先前创建的 DB2Command 时,将不克隆该 DB2Command。相反,SelectCommand 将保持对先前创建的 DB2Command 对象的引用。

如果 SelectCommand 不返回任何行,那么不会将表添加至 DataSet,并且不会引发异常。

示例

[Visual Basic, C#] 以下示例将创建 DB2DataAdapter 并设置它的某些属性。

[Visual Basic]
Public Sub CreateDB2DataAdapter()
     Dim myConnection As DB2Connection = New DB2Connection("DATABASE=SAMPLE")
     Dim myDataAdapter As New DB2DataAdapter()
     Dim mySelectCommand As New DB2Command()
     myDataAdapter.SelectCommand.CommandText = _
        "SELECT * FROM STAFF ORDER BY ID"
 End Sub

[C#]
public void CreateDB2DataAdapter () {
    DB2Connection myConnection = new DB2Connection("DATABASE=SAMPLE");
    DB2DataAdapter myDataAdapter = new DB2DataAdapter();
    DB2Command mySelectCommand = new DB2Command();
    myDataAdapter.SelectCommand.CommandText = "SELECT * FROM STAFF ORDER BY ID";
}