SqlCeDataAdapter.DeleteCommand Property

データ セットからレコードを削除する SQL ステートメントを取得または設定します。

名前空間: System.Data.SqlServerCe
アセンブリ: System.Data.SqlServerCe (system.data.sqlserverce.dll 内)

構文

'宣言
Public Property DeleteCommand As SqlCeCommand
public SqlCeCommand DeleteCommand { get; set; }
public:
property SqlCeCommand^ DeleteCommand {
    SqlCeCommand^ get ();
    void set (SqlCeCommand^ value);
}
/** @property */
public SqlCeCommand get_DeleteCommand ()

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

public function set DeleteCommand (value : SqlCeCommand)

プロパティ値

Update 処理中に、DataSet 内の削除行に対応するデータ ソース内のレコードを削除するための SqlCeCommand

解説

Update の呼び出し中に、このプロパティが設定されておらず、DataSet に主キー情報が存在する場合、SelectCommand プロパティを設定し、SqlCeCommandBuilder を使用しているときは、DeleteCommand が自動的に生成されます。続いて、設定していない追加のコマンドが、SqlCeCommandBuilder によって生成されます。この生成ロジックでは、DataSet 内にキー列情報が存在している必要があります。

作成済みの SqlCeCommandDeleteCommand が割り当てられた場合、SqlCeCommand のクローンは作成されません。DeleteCommand によって、作成済みの SqlCeCommand オブジェクトへの参照が維持されます。

SqlCeDataAdapter を作成し、そのプロパティの一部を設定する例を次に示します。

Dim cmd As SqlCeCommand = Nothing
Dim adp As SqlCeDataAdapter = Nothing

Try
    adp = New SqlCeDataAdapter()
    Dim conn As New SqlCeConnection("Data Source = MyDatabase.sdf")

    ' Create the SelectCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city"
    cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15)
    cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15)

    cmd.Parameters("@country").Value = "UK"
    cmd.Parameters("@city").Value = "London"

    adp.SelectCommand = cmd

    ' Create the DeleteCommand
    '
    cmd = conn.CreateCommand()
    cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID"

    Dim p As SqlCeParameter = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID")
    p.SourceVersion = DataRowVersion.Original

    adp.DeleteCommand = cmd

    ' Populate the dataset with the results from the SELECT statement
    '
    Dim ds As New DataSet()
    adp.Fill(ds)

    ' Modify the dataset
    '
    MessageBox.Show("Number of rows: " & ds.Tables(0).Rows.Count)

    ' Delete some rows
    '
    ds.Tables(0).Rows(3).Delete()
    ds.Tables(0).Rows(4).Delete()

    ' This will execute two DELETE statements 
    '
    adp.Update(ds.Tables(0))
Catch e As Exception
    MessageBox.Show(e.Message)
Finally
    If Not Nothing Is adp.SelectCommand Then
        adp.SelectCommand.Dispose()
    End If
    If Not Nothing Is adp.DeleteCommand Then
        adp.DeleteCommand.Dispose()
    End If
End Try
SqlCeCommand cmd = null;
SqlCeDataAdapter adp = null;

try
{
    adp = new SqlCeDataAdapter();
    SqlCeConnection conn = new SqlCeConnection("Data Source = MyDatabase.sdf");

    // Create the SelectCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "SELECT * FROM Orders WHERE [Ship Country] = @country AND [Ship City] = @city";
    cmd.Parameters.Add("@country", SqlDbType.NVarChar, 15);
    cmd.Parameters.Add("@city", SqlDbType.NVarChar, 15);

    cmd.Parameters["@country"].Value = "UK";
    cmd.Parameters["@city"].Value = "London";

    adp.SelectCommand = cmd;

    // Create the DeleteCommand
    //
    cmd = conn.CreateCommand();
    cmd.CommandText = "DELETE FROM Orders WHERE [Order ID] = @orderID";

    SqlCeParameter p = cmd.Parameters.Add("@orderID", SqlDbType.NChar, 5, "Order ID");
    p.SourceVersion = DataRowVersion.Original;

    adp.DeleteCommand = cmd;

    // Populate the dataset with the results from the SELECT statement
    //
    DataSet ds = new DataSet();
    adp.Fill(ds);

    // Modify the dataset
    //
    MessageBox.Show("Number of rows: " + ds.Tables[0].Rows.Count);

    // Delete some rows
    //
    ds.Tables[0].Rows[3].Delete();
    ds.Tables[0].Rows[4].Delete();

    // This will execute two DELETE statements 
    //
    adp.Update(ds.Tables[0]);
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}
finally
{
    if (null != adp.SelectCommand) adp.SelectCommand.Dispose();
    if (null != adp.DeleteCommand) adp.DeleteCommand.Dispose();
}

スレッド セーフ

この型の public static (Visual Basic では Shared ) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

開発プラットフォーム

Windows Vista、Windows Mobile 5.0、Windows XP Professional with Service Pack 2 (SP2)、Windows Server 2003、Windows Mobile 2003 for Pocket PC、Windows CE 5.0
バージョン情報
.NET Framework および .NET Compact Framework
3.5 でサポート
.NET Framework
3.0 でサポート
.NET Compact Framework および .Net Framework
2.0 でサポート

参照

リファレンス

SqlCeDataAdapter Class
SqlCeDataAdapter Members
System.Data.SqlServerCe Namespace
InsertCommand
SelectCommand
UpdateCommand