SqlErrorCollection.Count 속성

정의

컬렉션의 오류 수를 가져옵니다.

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

속성 값

컬렉션의 전체 오류 수입니다.

구현

예제

다음 예제에서는 각 SqlError 내에서 SqlErrorCollection 컬렉션입니다.

public static void ShowSqlException(string connectionString)
{
    string queryString = "EXECUTE NonExistantStoredProcedure";

    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        SqlCommand command = new SqlCommand(queryString, connection);
        try
        {
            command.Connection.Open();
            command.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            DisplaySqlErrors(ex);
        }
    }
}

private static void DisplaySqlErrors(SqlException exception)
{
    for (int i = 0; i < exception.Errors.Count; i++)
    {
        Console.WriteLine("Index #" + i + "\n" +
            "Error: " + exception.Errors[i].ToString() + "\n");
    }
    Console.ReadLine();
}
Public Sub ShowSqlException(ByVal connectionString As String)
    Dim queryString As String = "EXECUTE NonExistantStoredProcedure"

    Using connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)

        Try
            command.Connection.Open()
            command.ExecuteNonQuery()

        Catch ex As SqlException
            DisplaySqlErrors(ex)
        End Try
    End Using
End Sub

Private Sub DisplaySqlErrors(ByVal exception As SqlException)
    Dim i As Integer

    For i = 0 To exception.Errors.Count - 1
        Console.WriteLine("Index #" & i & ControlChars.NewLine & _
            "Error: " & exception.Errors(i).ToString() & ControlChars.NewLine)
    Next i
    Console.ReadLine()
End Sub

적용 대상

추가 정보