LinqDataSourceValidationException.InnerExceptions 屬性

定義

取得一個或多個在驗證新資料或修改資料時發生的例外。

public:
 property System::Collections::Generic::IDictionary<System::String ^, Exception ^> ^ InnerExceptions { System::Collections::Generic::IDictionary<System::String ^, Exception ^> ^ get(); };
public System.Collections.Generic.IDictionary<string,Exception> InnerExceptions { get; }
member this.InnerExceptions : System.Collections.Generic.IDictionary<string, Exception>
Public ReadOnly Property InnerExceptions As IDictionary(Of String, Exception)

屬性值

一個包含例外的集合。

實作

範例

以下範例展示了該 Updating 事件的事件處理程序。 它會透過控制 Label 項顯示任何驗證異常訊息。

Protected Sub LinqDataSource_Updating(ByVal sender As Object, _
        ByVal e As LinqDataSourceUpdateEventArgs)
    If (e.Exception IsNot Nothing) Then
        For Each innerException As KeyValuePair(Of String, Exception) _
                In e.Exception.InnerExceptions
          Label1.Text &= innerException.Key & ": " & _
                  innerException.Value.Message & "<br />"
        Next
        e.ExceptionHandled = True
    End If
End Sub
protected void LinqDataSource_Updating(object sender,
        LinqDataSourceUpdateEventArgs e)
{
    if (e.Exception != null)
    {
        foreach (KeyValuePair<string, Exception> innerException in
            e.Exception.InnerExceptions)
        {
            Label1.Text += innerException.Key + ": " +
                innerException.Message + "<br />";
        }
        e.ExceptionHandled = true;
    }
}

備註

InnerExceptions 集合包含在資料驗證過程中拋出的所有驗證例外,這些例外在更新、插入或刪除操作之前。 若值與屬性類型不符,則可能發生驗證例外。 例如,如果你嘗試用非數字字元更新整數屬性,會拋出驗證例外。 LINQ 轉 SQL 類別也可以包含客製化的驗證標準,確保屬性的值在預期範圍內或模式內。

適用於