OleDbCommand.ExecuteReader 메서드

정의

CommandTextConnection에 보내고 OleDbDataReader를 빌드합니다.

오버로드

ExecuteReader()

CommandTextConnection에 보내고 OleDbDataReader를 빌드합니다.

ExecuteReader(CommandBehavior)

CommandTextConnection에 보내고 CommandBehavior 값 중 하나를 사용하여 OleDbDataReader를 빌드합니다.

ExecuteReader()

CommandTextConnection에 보내고 OleDbDataReader를 빌드합니다.

public:
 System::Data::OleDb::OleDbDataReader ^ ExecuteReader();
public System.Data.OleDb.OleDbDataReader ExecuteReader ();
override this.ExecuteReader : unit -> System.Data.OleDb.OleDbDataReader
member this.ExecuteReader : unit -> System.Data.OleDb.OleDbDataReader
Public Function ExecuteReader () As OleDbDataReader

반환

OleDbDataReader

OleDbDataReader 개체입니다.

예외

연결이 원래 참여한 컨텍스트와 다른 트랜잭션 컨텍스트 내에서 명령을 실행할 수 없는 경우

예제

다음 예제 OleDbCommand에서는 SQL SELECT 문인 문자열과 데이터 원본에 연결하는 데 사용할 문자열을 전달하여 실행합니다.

public void CreateReader(string connectionString, string queryString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand(queryString, connection);
        connection.Open();
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Console.WriteLine(reader[0].ToString());
        }
        reader.Close();
    }
}
Public Sub CreateReader(ByVal connectionString As String, _
    ByVal queryString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand(queryString, connection)

        connection.Open()

        Dim reader As OleDbDataReader = command.ExecuteReader()
        While reader.Read()
            Console.WriteLine(reader(0).ToString())
        End While
        reader.Close()
    End Using
End Sub

설명

속성이 CommandType 설정 StoredProcedureCommandText 되면 속성을 저장 프로시저의 이름으로 설정해야 합니다. 이 명령은 호출 ExecuteReader할 때 이 저장 프로시저를 실행합니다.

닫기 OleDbConnection전에 먼저 개체를 OleDbDataReader 닫습니다. 개체를 OleDbDataReader 다시 사용 OleDbCommand 하려는 경우에도 개체를 닫아야 합니다.

추가 정보

적용 대상

ExecuteReader(CommandBehavior)

CommandTextConnection에 보내고 CommandBehavior 값 중 하나를 사용하여 OleDbDataReader를 빌드합니다.

public:
 System::Data::OleDb::OleDbDataReader ^ ExecuteReader(System::Data::CommandBehavior behavior);
public System.Data.OleDb.OleDbDataReader ExecuteReader (System.Data.CommandBehavior behavior);
override this.ExecuteReader : System.Data.CommandBehavior -> System.Data.OleDb.OleDbDataReader
member this.ExecuteReader : System.Data.CommandBehavior -> System.Data.OleDb.OleDbDataReader
Public Function ExecuteReader (behavior As CommandBehavior) As OleDbDataReader

매개 변수

behavior
CommandBehavior

CommandBehavior 값 중 하나입니다.

반환

OleDbDataReader

OleDbDataReader 개체입니다.

예외

연결이 원래 참여한 컨텍스트와 다른 트랜잭션 컨텍스트 내에서 명령을 실행할 수 없는 경우

예제

다음 예제 OleDbCommand에서는 Transact-SQL SELECT 문인 문자열과 데이터 원본에 연결하는 데 사용할 문자열을 전달하여 실행합니다. CommandBehaviorCloseConnection로 설정됩니다.

public void CreateMyOleDbDataReader(string queryString,string connectionString)
{
   OleDbConnection connection = new OleDbConnection(connectionString);
   OleDbCommand command = new OleDbCommand(queryString, connection);
   connection.Open();
   OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
   while(reader.Read())
   {
      Console.WriteLine(reader.GetString(0));
   }
   reader.Close();
   //Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
}
Public Sub CreateMyOleDbDataReader(queryString As String, _
    connectionString As String)
    Dim connection As New OleDbConnection(connectionString)
    Dim command As New OleDbCommand(queryString, connection)
    connection.Open()
    Dim reader As OleDbDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
    While reader.Read()
        Console.WriteLine(reader.GetString(0))
    End While
    reader.Close()
    'Implicitly closes the connection because CommandBehavior.CloseConnection was specified.
 End Sub

설명

개체의 OleDbCommand 메서드를 ExecuteReader 사용하여 지정 SingleRow 하면 .NET Framework Data Provider for OLE DB는 사용 가능한 경우 OLE DB IRow 인터페이스를 사용하여 바인딩을 수행합니다. 그렇지 않으면 IRowset 인터페이스를 사용합니다. SQL 문이 단일 행만 반환해야 하는 경우 SingleRow를 지정하여 애플리케이션의 성능을 향상시킬 수도 있습니다.

속성이 CommandType 설정 StoredProcedureCommandText 되면 속성을 저장 프로시저의 이름으로 설정해야 합니다. 이 명령은 호출 ExecuteReader할 때 이 저장 프로시저를 실행합니다.

큰 이 OleDbDataReader 진 값을 효율적으로 읽을 수 있는 특수 모드를 지원합니다. 자세한 내용은 에 대한 CommandBehavior설정을 참조하세요SequentialAccess.

닫기 OleDbConnection전에 먼저 개체를 OleDbDataReader 닫습니다. 개체를 OleDbDataReader 다시 사용 OleDbCommand 하려는 경우에도 개체를 닫아야 합니다. 설정하여 OleDbDataReader 만든 CommandBehavior 경우 연결을 닫 OleDbDataReader 으면 연결이 CloseConnection자동으로 닫힙니다.

추가 정보

적용 대상