ListViewInsertedEventArgs.AffectedRows プロパティ

定義

挿入操作の影響を受けた行の数を取得します。

public:
 property int AffectedRows { int get(); };
public int AffectedRows { get; }
member this.AffectedRows : int
Public ReadOnly Property AffectedRows As Integer

プロパティ値

挿入操作の影響を受けた行の数。

次の例は、イベントの ListViewInsertedEventArgs ハンドラー ItemInserted に渡される オブジェクトを使用して、挿入操作中に例外が発生したかどうかを判断する方法を示しています。 このコード例は、ListViewInsertedEventArgs クラスのために提供されている大規模な例の一部です。

void ContactsListView_ItemInserted(Object sender, ListViewInsertedEventArgs e)
{
  if (e.Exception != null)
  {
    if (e.AffectedRows == 0)
    {
      e.KeepInInsertMode = true;
      Message.Text = "An exception occurred inserting the new Contact. " +
        "Please verify your values and try again.";
    }
    else
      Message.Text = "An exception occurred inserting the new Contact. " +
        "Please verify the values in the newly inserted item.";

    e.ExceptionHandled = true;
  }
}
Sub ContactsListView_ItemInserted(ByVal sender As Object, ByVal e As ListViewInsertedEventArgs)

  If e.Exception IsNot Nothing Then

    If e.AffectedRows = 0 Then
      e.KeepInInsertMode = True
      Message.Text = "An exception occurred inserting the new Contact. " & _
        "Please verify your values and try again."
    Else
      Message.Text = "An exception occurred inserting the new Contact. " & _
        "Please verify the values in the newly inserted item."
    End If

    e.ExceptionHandled = True
  End If
End Sub

注釈

プロパティを AffectedRows 使用して、データ ソース コントロールから返される挿入操作の影響を受けたレコードの数を確認します。 このプロパティは、通常、次のシナリオで使用されます。

  • 1 つのレコードのみが挿入されたことを確認します。 誤って記述された insert ステートメントが複数のレコードを挿入する場合があります。

  • 挿入操作中にエラーが発生したためにレコードが挿入されなかったが、例外が発生しなかったことを確認するため。

  • 競合検出 (オプティミスティック コンカレンシー) をサポートするデータ ソース コントロールのプロパティが列挙値にConflictOptions.CompareAllValues設定されているときに、レコードがConflictDetection挿入されたことを確認します。 このプロパティをサポートするコントロールには、 SqlDataSource コントロールと ObjectDataSource コントロールが含まれます。 プロパティにこの値が設定されている場合、別のユーザーが挿入したレコードと同じキー値を持つレコードが挿入されないことがあります。

適用対象

こちらもご覧ください