共用方式為


SqlCeException.Errors 屬性

取得一個或多個SqlCeError 物件的集合,這些物件包含由 .NET Compact Framework Data Provider for SQL Server Compact 所產生之例外狀況的相關詳細資訊。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
Public Property Errors As SqlCeErrorCollection
    Get
    Private Set
'用途
Dim instance As SqlCeException
Dim value As SqlCeErrorCollection

value = instance.Errors
public SqlCeErrorCollection Errors { get; private set; }
public:
property SqlCeErrorCollection^ Errors {
    SqlCeErrorCollection^ get ();
    private: void set (SqlCeErrorCollection^ value);
}
member Errors : SqlCeErrorCollection with get, private set
function get Errors () : SqlCeErrorCollection
private function set Errors (value : SqlCeErrorCollection)

屬性值

型別:System.Data.SqlServerCe.SqlCeErrorCollection
SqlCeErrorCollection 物件,包含針對例外狀況所收集的 SqlCeError 類別的執行個體。

備註

SqlCeErrorCollection 類別一定會至少包含一個 SqlCeError 類別的執行個體。

範例

下列範例會顯示 SqlCeErrorCollection 集合內的每個 SqlCeError

Try
    Dim repl As New SqlCeReplication()

    ' Fill repl properites here
    ' ...
    ' SqlCeReplication may throw SqlCeException which contains a 
    ' collection of errors; SQL Mobile database engine always
    ' returns one error in the collection
    '
    repl.Synchronize()
Catch e As SqlCeException
    Dim err As SqlCeError
    For Each err In e.Errors
        ' Use SqlCeError properties if you need specific
        ' application logic depending on the error condition
        '
        If 28577 = [err].NativeError Then 'SSCE_M_SCHEMAHASCHANGED
            ' Error specific logic goes here...
            '
        End If

        ' Note: For native error numbers, refer to SQL Server Mobile Errors
        ' in the SQL Server Mobile Books Online
        '
        MessageBox.Show([err].Message)
    Next err
End Try
try
{
    SqlCeReplication repl = new SqlCeReplication();

    // Fill repl properites here
    // ...

    // SqlCeReplication may throw SqlCeException which contains a 
    // collection of errors; SQL Mobile database engine always
    // returns one error in the collection
    //
    repl.Synchronize();
}
catch (SqlCeException e)
{
    foreach (SqlCeError error in e.Errors)
    {
        // Use SqlCeError properties if you need specific
        // application logic depending on the error condition
        //
        if (28577 == error.NativeError /*SSCE_M_SCHEMAHASCHANGED*/)
        {
            // Error specific logic goes here...
            //
        }

        // Note: For native error numbers, refer to SQL Server Mobile Errors
        // in the SQL Server Mobile Books Online
        //
        MessageBox.Show(error.Message);
    }
}

請參閱

參考

SqlCeException 類別

System.Data.SqlServerCe 命名空間