OdbcError.SQLState 属性

定义

获取符合数据库的 ANSI SQL 标准的五字符错误代码。

public:
 property System::String ^ SQLState { System::String ^ get(); };
public string SQLState { get; }
member this.SQLState : string
Public ReadOnly Property SQLState As String

属性值

五个字符的错误代码,它确定错误的来源(如果错误可能来自不止一个地方)。

示例

以下示例显示 的属性 OdbcError

public void DisplayOdbcErrorCollection(OdbcException exception)
{
    for (int i = 0; i < exception.Errors.Count; i++)
    {
        Console.WriteLine("Index #" + i + "\n" +
            "Message: " + exception.Errors[i].Message + "\n" +
            "Native: " + exception.Errors[i].NativeError.ToString() + "\n" +
            "Source: " + exception.Errors[i].Source + "\n" +
            "SQL: " + exception.Errors[i].SQLState + "\n");
    }
    Console.ReadLine();
}
Public Sub DisplayOdbcErrorCollection(ByVal exception As OdbcException)
    Dim i As Integer

    For i = 0 To exception.Errors.Count - 1
        Console.WriteLine("Index #" & i.ToString() & ControlChars.Cr _
           & "Message: " & exception.Errors(i).Message & ControlChars.Cr _
           & "Native: " & exception.Errors(i).NativeError.ToString() & ControlChars.Cr _
           & "Source: " & exception.Errors(i).Source & ControlChars.Cr _
           & "SQL: " & exception.Errors(i).SQLState & ControlChars.Cr)
    Next i
    Console.ReadLine()
End Sub

适用于

另请参阅