请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
 DeleteCommand 属性

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
SqlDataAdapter.DeleteCommand 属性

获取或设置一个 Transact-SQL 语句或存储过程,以从数据集删除记录。

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

Visual Basic(声明)
Public Property DeleteCommand As SqlCommand
Visual Basic(用法)
Dim instance As SqlDataAdapter
Dim value As SqlCommand

value = instance.DeleteCommand

instance.DeleteCommand = value
C#
public SqlCommand DeleteCommand { get; set; }
C++
public:
property SqlCommand^ DeleteCommand {
    SqlCommand^ get ();
    void set (SqlCommand^ value);
}
J#
/** @property */
public SqlCommand get_DeleteCommand ()

/** @property */
public void set_DeleteCommand (SqlCommand value)
JScript
public function get DeleteCommand () : SqlCommand

public function set DeleteCommand (value : SqlCommand)

属性值

Update 过程中使用 SqlCommand,以在数据库中删除对应于 DataSet 中已删除行的记录。

Update 过程中,如果未设置此属性而且 DataSet 中存在主键信息,那么在设置 SelectCommand 属性并使用 SqlCommandBuilder 的情况下,可以自动生成 DeleteCommand。然后,SqlCommandBuilder 将生成其他任何未设置的命令。此生成逻辑要求 DataSet 中存在键列信息。有关更多信息,请参见 自动生成命令

在将 DeleteCommand 分配给以前创建的 SqlCommand 时,不克隆 SqlCommandDeleteCommand 维护对以前创建的 SqlCommand 对象的引用。

TopicLocation
如何:允许用户删除 DataList Web 服务器控件中的项生成 ASP .NET Web 应用程序
如何:允许用户删除 DataList Web 服务器控件中的项在 Visual Studio 中生成 ASP .NET Web 应用程序

下面的示例将创建一个 SqlDataAdapter,并设置 SelectCommandInsertCommandUpdateCommandDeleteCommand 属性。假定已经创建一个 SqlConnection 对象。

Visual Basic
Public Function CreateCustomerAdapter( _
  ByVal connection As SqlConnection) As SqlDataAdapter

    Dim adapter As SqlDataAdapter = New SqlDataAdapter()

    ' Create the SelectCommand.
    Dim command As SqlCommand = New SqlCommand( _
        "SELECT * FROM Customers " & _
        "WHERE Country = @Country AND City = @City", connection)

    ' Add the parameters for the SelectCommand.
    command.Parameters.Add("@Country", SqlDbType.NVarChar, 15)
    command.Parameters.Add("@City", SqlDbType.NVarChar, 15)

    adapter.SelectCommand = command

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

    ' Add the parameters for the InsertCommand.
    command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
    command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName")

    adapter.InsertCommand = command

    ' Create the UpdateCommand.
    command = New SqlCommand( _
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " & _
        "WHERE CustomerID = @oldCustomerID", connection)

    ' Add the parameters for the UpdateCommand.
    command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
    command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName")
    Dim parameter As SqlParameter = command.Parameters.Add( _
        "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID")
    parameter.SourceVersion = DataRowVersion.Original

    adapter.UpdateCommand = command

    ' Create the DeleteCommand.
    command = New SqlCommand( _
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection)

    ' Add the parameters for the DeleteCommand.
    command.Parameters.Add( _
        "@CustomerID", SqlDbType.NChar, 5, "CustomerID")
    parameter.SourceVersion = DataRowVersion.Original

    adapter.DeleteCommand = command

    Return adapter
End Function
C#
public static SqlDataAdapter CreateCustomerAdapter(
    SqlConnection connection)
{
    SqlDataAdapter adapter = new SqlDataAdapter();

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

    // Add the parameters for the SelectCommand.
    command.Parameters.Add("@Country", SqlDbType.NVarChar, 15);
    command.Parameters.Add("@City", SqlDbType.NVarChar, 15);

    adapter.SelectCommand = command;

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

    // Add the parameters for the InsertCommand.
    command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
    command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");

    adapter.InsertCommand = command;

    // Create the UpdateCommand.
    command = new SqlCommand(
        "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " +
        "WHERE CustomerID = @oldCustomerID", connection);

    // Add the parameters for the UpdateCommand.
    command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
    command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");
    SqlParameter parameter = command.Parameters.Add(
        "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID");
    parameter.SourceVersion = DataRowVersion.Original;

    adapter.UpdateCommand = command;

    // Create the DeleteCommand.
    command = new SqlCommand(
        "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);

    // Add the parameters for the DeleteCommand.
    parameter = command.Parameters.Add(
        "@CustomerID", SqlDbType.NChar, 5, "CustomerID");
    parameter.SourceVersion = DataRowVersion.Original;

    adapter.DeleteCommand = 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
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker