ListViewUpdatedEventArgs.AffectedRows 屬性

定義

取得更新作業所影響的資料列數目。

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

屬性值

Int32

更新作業所影響的資料列數目。

範例

下列範例示範如何使用 AffectedRows 屬性來確認專案已更新。 此程式碼範例是針對 類別提供的較大範例的 ListViewUpdatedEventArgs 一部分。

void ContactsListView_ItemUpdated(Object sender, ListViewUpdatedEventArgs e)
{
    if (e.Exception != null)
    {
        if (e.AffectedRows == 0)
        {
            e.KeepInEditMode = true;
            Message.Text = "An exception occurred updating the contact. " +
                                "Please verify your values and try again.";
        }
        else
            Message.Text = "An exception occurred updating the contact. " +
                                "Please verify the values in the recently updated item.";

        e.ExceptionHandled = true;
    }
}
Sub ContactsListView_ItemUpdated(sender As Object, e As ListViewUpdatedEventArgs)
    If e.Exception IsNot Nothing Then
        If e.AffectedRows = 0 Then
            e.KeepInEditMode = True
            Message.Text = "An exception occurred updating the contact. " & _
                                "Please verify your values and try again."
        Else
            Message.Text = "An exception occurred updating the contact. " & _
                                "Please verify the values in the recently updated item."
        End If

        e.ExceptionHandled = True
    End If
End Sub

備註

AffectedRows使用 屬性來判斷受更新作業影響的資料列數目,如資料來源所傳回。 因為通常只會更新一個專案,所以此屬性通常包含 0 或 1 的值。

有時候在更新作業期間,可能會發生未引發例外狀況的錯誤。 在此情況下, AffectedRows 可以使用 屬性來確認專案已更新。

適用於

另請參閱