Bagikan melalui


ListViewUpdatedEventArgs.AffectedRows Properti

Definisi

Mendapatkan jumlah baris yang terpengaruh oleh operasi pembaruan.

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

Nilai Properti

Jumlah baris yang terpengaruh oleh operasi pembaruan.

Contoh

Contoh berikut menunjukkan cara menggunakan AffectedRows properti untuk memverifikasi bahwa item telah diperbarui. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ListViewUpdatedEventArgs kelas .

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

Keterangan

AffectedRows Gunakan properti untuk menentukan jumlah baris yang terpengaruh oleh operasi pembaruan, seperti yang dikembalikan oleh sumber data. Karena biasanya hanya satu item yang diperbarui, properti ini biasanya berisi nilai 0 atau 1.

Terkadang selama operasi pembaruan, kesalahan dapat terjadi yang tidak menimbulkan pengecualian. Dalam hal ini, AffectedRows properti dapat digunakan untuk memverifikasi bahwa item telah diperbarui.

Berlaku untuk

Lihat juga