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 to SQL類別也可以包含自訂的驗證準則,以確保屬性包含預期範圍或模式內的值。

適用於