utility.vb

来自「嵌入式系统的发展异常迅速」· VB 代码 · 共 41 行

VB
41
字号
Imports System.Data.SqlServerCe
Imports System.Data.SqlServerCe.SqlCeException
Imports System.text
Public Class Utility

    Public Function ComposeSqlErrorMessage(ByVal e As SqlCeException) As String
        Dim errorCollection As SqlCeErrorCollection = e.Errors
        Dim bld As New StringBuilder
        Dim inner As Exception = e.InnerException
        ' Compose SQL Server CE error information into a single string
        If Not (inner Is Nothing) Then
            bld.Append(("Inner Exception: " & inner.ToString()))
        End If

        Dim err As SqlCeError
        For Each err In errorCollection
            bld.Append(ControlChars.Cr & "Error:" & err.HResult.ToString("X"))
            bld.Append(ControlChars.Cr & err.Message)
            bld.Append(ControlChars.Cr & "Native Error:" & err.NativeError)
            bld.Append(ControlChars.Cr & err.Source)

            Dim numPar As Integer
            For Each numPar In err.NumericErrorParameters
                If numPar <> 0 Then
                    bld.Append(ControlChars.Cr & "N-Parm:" & numPar.ToString())
                End If
            Next numPar
            Dim errPar As String
            For Each errPar In err.ErrorParameters
                If errPar <> [String].Empty Then
                    bld.Append(ControlChars.Cr & "E-Parm:" & errPar)
                End If
            Next errPar
        Next err

        Return bld.ToString()

    End Function

End Class

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?