OleDbDataAdapter.DeleteCommand 属性
获取或设置 SQL 语句或存储过程,用于从数据集中删除记录。
**命名空间:**System.Data.OleDb
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public Property DeleteCommand As OleDbCommand
用法
Dim instance As OleDbDataAdapter
Dim value As OleDbCommand
value = instance.DeleteCommand
instance.DeleteCommand = value
public OleDbCommand DeleteCommand { get; set; }
public:
property OleDbCommand^ DeleteCommand {
OleDbCommand^ get ();
void set (OleDbCommand^ value);
}
/** @property */
public OleDbCommand get_DeleteCommand ()
/** @property */
public void set_DeleteCommand (OleDbCommand value)
public function get DeleteCommand () : OleDbCommand
public function set DeleteCommand (value : OleDbCommand)
属性值
在 Update 过程中使用的 OleDbCommand,用以删除数据源中与 DataSet 中已删除的行相对应的记录。
备注
在 Update 过程中,如果未设置此属性而且 DataSet 中存在主键信息,那么在设置 SelectCommand 属性并使用 OleDbCommandBuilder 的情况下,可以自动生成 DeleteCommand。然后,OleDbCommandBuilder 将生成其他任何未设置的命令。此生成逻辑要求 DataSet 中存在键列信息。有关更多信息,请参见 自动生成命令。
在将 DeleteCommand 分配给以前创建的 OleDbCommand 时,不克隆 OleDbCommand。DeleteCommand 维护对以前创建的 OleDbCommand 对象的引用。
示例
下面的示例创建一个 OleDbDataAdapter 并设置 SelectCommand 和 DeleteCommand 属性。假定已经创建了一个 OleDbConnection 对象。
Public Shared Function CreateCustomerAdapter( _
connection As OleDbConnection) As OleDbDataAdapter
Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter()
Dim command As OleDbCommand
Dim parameter As OleDbParameter
' Create the SelectCommand.
command = New OleDbCommand("SELECT CustomerID FROM Customers " & _
"WHERE Country = ? AND City = ?", connection)
command.Parameters.Add("Country", OleDbType.VarChar, 15)
command.Parameters.Add("City", OleDbType.VarChar, 15)
dataAdapter.SelectCommand = command
' Create the DeleteCommand.
command = New OleDbCommand( _
"DELETE * FROM Customers WHERE CustomerID = ?", _
connection)
parameter = command.Parameters.Add( _
"CustomerID", OleDbType.Char, 5, "CustomerID")
parameter.SourceVersion = DataRowVersion.Original
dataAdapter.DeleteCommand = command
Return dataAdapter
End Function
public static OleDbDataAdapter CreateCustomerAdapter(
OleDbConnection connection)
{
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
OleDbCommand command;
OleDbParameter parameter;
// Create the SelectCommand.
command = new OleDbCommand("SELECT CustomerID FROM Customers " +
"WHERE Country = ? AND City = ?", connection);
command.Parameters.Add("Country", OleDbType.VarChar, 15);
command.Parameters.Add("City", OleDbType.VarChar, 15);
dataAdapter.SelectCommand = command;
// Create the DeleteCommand.
command = new OleDbCommand(
"DELETE * FROM Customers WHERE CustomerID = ?",
connection);
parameter = command.Parameters.Add(
"CustomerID", OleDbType.Char, 5, "CustomerID");
parameter.SourceVersion = DataRowVersion.Original;
dataAdapter.DeleteCommand = command;
return dataAdapter;
}
平台
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 命名空间