SqlErrorCollection 클래스

정의

.NET Framework Data Provider for SQL Server에서 생성된 오류를 모두 수집합니다. 이 클래스는 상속될 수 없습니다.

public ref class SqlErrorCollection sealed : System::Collections::ICollection
public sealed class SqlErrorCollection : System.Collections.ICollection
[System.ComponentModel.ListBindable(false)]
[System.Serializable]
public sealed class SqlErrorCollection : System.Collections.ICollection
type SqlErrorCollection = class
    interface ICollection
    interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
[<System.Serializable>]
type SqlErrorCollection = class
    interface ICollection
    interface IEnumerable
Public NotInheritable Class SqlErrorCollection
Implements ICollection
상속
SqlErrorCollection
특성
구현

예제

다음 예제에서는 각 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

설명

이 클래스는 클래스의 SqlError 인스턴스를 수집하기 위해 만들어집니다SqlException. SqlErrorCollection 는 항상 클래스의 SqlError 인스턴스를 하나 이상 포함합니다.

속성

Count

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

Item[Int32]

지정된 인덱스의 오류를 가져옵니다.

메서드

CopyTo(Array, Int32)

SqlErrorCollection 컬렉션의 요소를 Array의 지정된 인덱스에서 시작하는 위치에 복사합니다.

CopyTo(SqlError[], Int32)

SqlErrorCollection 컬렉션의 요소를 SqlErrorCollection의 지정된 인덱스에서 시작하는 위치에 복사합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetEnumerator()

SqlErrorCollection를 반복하는 열거자를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.IsSynchronized

이 멤버에 대한 설명은 IsSynchronized를 참조하세요.

ICollection.SyncRoot

이 멤버에 대한 설명은 SyncRoot를 참조하세요.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보