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 类还可以包含自定义的验证条件,以确保该属性包含一个值,该值位于预期范围或模式内。

适用于