IDbDataAdapter.SelectCommand 属性

获取或设置用于在数据源中选择记录的 SQL 语句。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Property SelectCommand As IDbCommand
用法
Dim instance As IDbDataAdapter
Dim value As IDbCommand

value = instance.SelectCommand

instance.SelectCommand = value
IDbCommand SelectCommand { get; set; }
property IDbCommand^ SelectCommand {
    IDbCommand^ get ();
    void set (IDbCommand^ value);
}
/** @property */
IDbCommand get_SelectCommand ()

/** @property */
void set_SelectCommand (IDbCommand value)
function get SelectCommand () : IDbCommand

function set SelectCommand (value : IDbCommand)

属性值

Update 过程中使用的 IDbCommand,它从数据源中选择记录以便放入数据集中。

备注

在将 SelectCommand 分配给以前创建的 IDbCommand 时,不克隆 IDbCommandSelectCommand 维护对以前创建的 IDbCommand 对象的引用。

如果 SelectCommand 不返回任何行,则没有任何表添加到 DataSet 中,并且不会引发任何异常。

示例

下面的示例创建继承的 OleDbDataAdapter 类的实例,并设置 SelectCommandInsertCommand 属性。假定已经创建了一个 OleDbConnection 对象。

Public Shared Function CreateCustomerAdapter( _
    connection As OleDbConnection) As OleDbDataAdapter 

    Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
    Dim command As OleDbCommand

    ' Create the SelectCommand.
    command = New OleDbCommand("SELECT * FROM Customers " & _
        "WHERE Country = ? AND City = ?", connection)

    command.Parameters.Add("Country", OleDbType.VarChar, 15)
    command.Parameters.Add("City", OleDbType.VarChar, 15)

    adapter.SelectCommand = command

    ' Create the InsertCommand.
    command = New OleDbCommand( _
        "INSERT INTO Customers (CustomerID, CompanyName) " & _
        "VALUES (?, ?)", connection)

    command.Parameters.Add( _
        "CustomerID", OleDbType.Char, 5, "CustomerID")
    command.Parameters.Add( _
        "CompanyName", OleDbType.VarChar, 40, "CompanyName")

    adapter.InsertCommand = command
    Return adapter
End Function
public static OleDbDataAdapter CreateCustomerAdapter(
    OleDbConnection connection)
{
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    OleDbCommand command;

    // Create the SelectCommand.
    command = new OleDbCommand("SELECT * FROM Customers " +
        "WHERE Country = ? AND City = ?", connection);

    command.Parameters.Add("Country", OleDbType.VarChar, 15);
    command.Parameters.Add("City", OleDbType.VarChar, 15);

    adapter.SelectCommand = command;

    // Create the InsertCommand.
    command = new OleDbCommand(
        "INSERT INTO Customers (CustomerID, CompanyName) " +
        "VALUES (?, ?)", connection);

    command.Parameters.Add(
        "CustomerID", OleDbType.Char, 5, "CustomerID");
    command.Parameters.Add(
        "CompanyName", OleDbType.VarChar, 40, "CompanyName");

    adapter.InsertCommand = command;
    return adapter;
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

IDbDataAdapter 接口
IDbDataAdapter 成员
System.Data 命名空间