OleDbDataAdapter.SelectCommand 属性
获取或设置 SQL 语句或存储过程,用于选择数据源中的记录。
**命名空间:**System.Data.OleDb
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public Property SelectCommand As OleDbCommand
用法
Dim instance As OleDbDataAdapter
Dim value As OleDbCommand
value = instance.SelectCommand
instance.SelectCommand = value
public OleDbCommand SelectCommand { get; set; }
public:
property OleDbCommand^ SelectCommand {
OleDbCommand^ get ();
void set (OleDbCommand^ value);
}
/** @property */
public OleDbCommand get_SelectCommand ()
/** @property */
public void set_SelectCommand (OleDbCommand value)
public function get SelectCommand () : OleDbCommand
public function set SelectCommand (value : OleDbCommand)
属性值
在 Fill 过程中使用的 OleDbCommand,用于从数据源中选择要放在 DataSet 中的记录。
备注
在将 SelectCommand 分配给以前创建的 OleDbCommand 时,不克隆 OleDbCommand。SelectCommand 维护对以前创建的 OleDbCommand 对象的引用。
如果 SelectCommand 不返回任何行,则不会向 DataSet 中添加任何表,并且不会引发任何异常。
示例
下面的示例创建一个 OleDbDataAdapter 并设置 SelectCommand 和 InsertCommand 属性。假定已经创建了一个 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 Millennium Edition、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
请参见
参考
OleDbDataAdapter 类
OleDbDataAdapter 成员
System.Data.OleDb 命名空间