SqlState 属性

       

返回 SQL 状态错误。String 类型,只读。

说明

有关特定错误的解释,请参阅 SQL 文档。

示例

本示例刷新查询表一,并显示产生的所有 ODBC 错误。

With Worksheets(1).QueryTables(1)
    .Refresh
    Set errs = Application.ODBCErrors
    If errs.Count > 0 Then
        Set r = .Destination.Cells(1)
        r.Value = "The following errors occurred:"
        c = 0
        For Each er In errs
            c = c + 1
            r.offset(c, 0).value = er.ErrorString
            r.offset(c, 1).value = er.SqlState
        Next
    Else
        MsgBox "Query complete: all records returned."
    End If
End With