DbDataReader.GetInt32(Int32) 메서드

정의

파생 클래스에서 재정의되는 경우 지정된 열의 값을 32비트 부호 있는 정수로 가져옵니다.

public:
 abstract int GetInt32(int ordinal);
public abstract int GetInt32 (int ordinal);
abstract member GetInt32 : int -> int
Public MustOverride Function GetInt32 (ordinal As Integer) As Integer

매개 변수

ordinal
Int32

열 서수(0부터 시작)입니다.

반환

지정된 열의 값입니다.

구현

예외

열 인덱스가 범위를 벗어났습니다.

지정된 캐스트가 잘못된 경우

설명

private static void GetCredits(String connectionString)
{
    using (SqlConnection conn = new SqlConnection(connectionString))
    {
        String queryString = "Select [CourseID],[Title],[Credits] from [MySchool].[dbo].[Course]";
        using (DbCommand command = new SqlCommand(queryString, conn))
        {
            conn.Open();
            using (DbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    // Credits column is the integer column, and you can use the GetInt32 method
                    // to return a 32-bit signed integer.
                    Console.WriteLine("Course:{0,-15} Credits:{1}",reader[1],reader.GetInt32(2));
                }
            }
        }
    }
}

적용 대상

추가 정보