ListViewInsertedEventArgs.AffectedRows 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得插入作業所影響的資料列數目。
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使用 屬性來判斷受插入作業影響的記錄數目,如資料來源控制項所傳回。 此屬性通常用於下列案例:
確認只插入單一記錄。 有時候寫入錯誤的 insert 語句可以插入多個記錄。
若要確認記錄未插入,因為插入作業期間發生錯誤,但未引發例外狀況。
若要確認當支援衝突偵測的資料來源控制項 (開放式平行存取) 的 ConflictDetection 屬性設定為
ConflictOptions.CompareAllValues
列舉值時,已插入記錄。 支援此屬性的 SqlDataSource 控制項包括 和 ObjectDataSource 控制項。 當 屬性具有這個值時,如果記錄的索引鍵值與其他使用者所插入的記錄相同,則可能不會插入記錄。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應