SqlDataAdapter.DeleteCommand 속성

정의

레코드를 데이터 집합으로부터 삭제할 Transact-SQL 문이나 저장 프로시저를 가져오거나 설정합니다.

public:
 property System::Data::SqlClient::SqlCommand ^ DeleteCommand { System::Data::SqlClient::SqlCommand ^ get(); void set(System::Data::SqlClient::SqlCommand ^ value); };
public System.Data.SqlClient.SqlCommand DeleteCommand { get; set; }
[System.Data.DataSysDescription("DbDataAdapter_DeleteCommand")]
public System.Data.SqlClient.SqlCommand DeleteCommand { get; set; }
member this.DeleteCommand : System.Data.SqlClient.SqlCommand with get, set
[<System.Data.DataSysDescription("DbDataAdapter_DeleteCommand")>]
member this.DeleteCommand : System.Data.SqlClient.SqlCommand with get, set
Public Property DeleteCommand As SqlCommand

속성 값

SqlCommand의 삭제된 행과 일치하는 데이터베이스의 레코드를 삭제하는 Update(DataSet) 중에 사용되는 DataSet입니다.

특성

예제

다음 예제에서는 를 만들고 SqlDataAdapter , , InsertCommandUpdateCommandDeleteCommand 속성을 설정합니다SelectCommand. 개체를 이미 만들었다고 가정합니다 SqlConnection .

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;
}
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

설명

중에 Update이 속성이 설정되지 않고 기본 키 정보가 에 DataSetDeleteCommand 있는 경우 속성을 설정하고 SelectCommand 를 사용하면 SqlCommandBuilder가 자동으로 생성될 수 있습니다. 그런 다음, 설정하지 않은 추가 명령은 에 의해 SqlCommandBuilder생성됩니다. 이 세대 논리에 키 열 정보가 필요 합니다 DataSet합니다. 자세한 내용은 CommandBuilder를 사용하여 명령 생성을 참조하세요.

DeleteCommand 가 이전에 만든 SqlCommand에 할당되면 가 SqlCommand 복제되지 않습니다. 는 DeleteCommand 이전에 만든 SqlCommand 개체에 대한 참조를 유지 관리합니다.

의 데이터 원본에 전파하는 모든 열에 대해 Update, 또는 DeleteCommand에 매개 변수를 InsertCommandUpdateCommand추가해야 합니다. SourceColumn 매개 변수의 속성을 열 이름으로 설정해야 합니다. 이는 매개 변수의 값이 수동으로 설정되지 않았지만 현재 처리된 행의 특정 열에서 가져온 것임을 나타냅니다.

적용 대상

추가 정보