共用方式為


OleDbError.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

屬性值

五個字元的錯誤碼,如果可以從一個以上的位置發出錯誤,則會識別錯誤的來源。

範例

下列範例會顯示的屬性 OleDbError

public void DisplayOleDbErrorCollection(OleDbException 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 DisplayOleDbErrorCollection(ByVal exception As OleDbException)
    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

適用於

另請參閱