Bagikan melalui


ListViewInsertedEventArgs.AffectedRows Properti

Definisi

Mendapatkan jumlah baris yang terpengaruh oleh operasi sisipkan.

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 dipengaruhi oleh operasi sisipkan.

Contoh

Contoh berikut menunjukkan cara menggunakan ListViewInsertedEventArgs objek yang diteruskan ke handler untuk ItemInserted peristiwa guna menentukan apakah pengecualian dinaikkan selama operasi penyisipan. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ListViewInsertedEventArgs kelas .

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

Keterangan

AffectedRows Gunakan properti untuk menentukan jumlah rekaman yang terpengaruh oleh operasi penyisipan, seperti yang dikembalikan oleh kontrol sumber data. Properti ini biasanya digunakan dalam skenario berikut:

  • Untuk memverifikasi bahwa hanya satu rekaman yang disisipkan. Terkadang pernyataan penyisipan yang salah ditulis dapat menyisipkan beberapa rekaman.

  • Untuk memverifikasi bahwa rekaman tidak disisipkan karena terjadi kesalahan selama operasi penyisipan, tetapi pengecualian tidak dimunculkan.

  • Untuk memverifikasi bahwa rekaman disisipkan saat kontrol sumber data yang mendukung deteksi konflik (konkurensi optimis) memiliki properti yang ConflictDetection diatur ke ConflictOptions.CompareAllValues nilai enumerasi. Kontrol yang mendukung properti ini mencakup SqlDataSource kontrol dan ObjectDataSource . Saat properti memiliki nilai ini, rekaman mungkin tidak disisipkan jika memiliki nilai kunci yang sama dengan rekaman yang disisipkan oleh pengguna lain.

Berlaku untuk

Lihat juga