DataTableReader.Item[] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 열의 값을 네이티브 형식으로 가져옵니다.
오버로드
| Name | Description |
|---|---|
| Item[Int32] |
열 서수가 지정된 경우 지정된 열의 값을 네이티브 형식으로 가져옵니다. |
| Item[String] |
열 이름이 지정된 경우 지정된 열의 값을 네이티브 형식으로 가져옵니다. |
Item[Int32]
열 서수가 지정된 경우 지정된 열의 값을 네이티브 형식으로 가져옵니다.
public:
virtual property System::Object ^ default[int] { System::Object ^ get(int ordinal); };
public override object this[int ordinal] { get; }
member this.Item(int) : obj
Default Public Overrides ReadOnly Property Item(ordinal As Integer) As Object
매개 변수
- ordinal
- Int32
0부터 시작하는 열 서수입니다.
속성 값
지정된 열의 네이티브 형식 값입니다.
예외
전달된 인덱스가 0에서 1까지 FieldCount 의 범위를 벗어났습니다.
예제
다음 예제에서는 제공 DataTableReader된 모든 행에 있는 모든 열의 내용을 표시합니다. 이 코드는 Item[] 메서드(Microsoft C#의 인덱서)를 사용하여 각 열에 포함된 값을 검색합니다.
private static void DisplayItems(DataTableReader reader)
{
int rowNumber = 0;
while (reader.Read())
{
Console.WriteLine("Row " + rowNumber);
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine("{0}: {1}", reader.GetName(i), reader[i]);
}
rowNumber++;
}
}
Private Sub DisplayItems(ByVal reader As DataTableReader)
Dim rowNumber As Integer
While reader.Read()
Console.WriteLine("Row " & rowNumber)
For i As Integer = 0 To reader.FieldCount - 1
Console.WriteLine("{0}: {1}", reader.GetName(i), reader.Item(i))
Next
rowNumber += 1
End While
End Sub
설명
이 Item[] 오버로드는 메서드와 동일하게 GetValue 동작합니다.
추가 정보
적용 대상
Item[String]
열 이름이 지정된 경우 지정된 열의 값을 네이티브 형식으로 가져옵니다.
public:
virtual property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ name); };
public override object this[string name] { get; }
member this.Item(string) : obj
Default Public Overrides ReadOnly Property Item(name As String) As Object
매개 변수
- name
- String
열 이름입니다.
속성 값
지정된 열의 네이티브 형식 값입니다.
예외
지정한 이름이 올바른 열 이름이 아닙니다.
삭제된 행에서 데이터를 검색하려고 했습니다.
닫힌 DataTableReader열의 열을 읽거나 액세스하려고 했습니다.
예제
DataTableReader 열 이름 및 열 이름을 지정하면 GetValueByName 프로시저는 지정된 열의 값을 반환합니다. 이 프로시저를 호출하기 전에 새 DataTableReader 인스턴스를 만들고 해당 Read 메서드를 한 번 이상 호출하여 행 포인터를 데이터 행에 배치해야 합니다.
private static object GetValueByName(
DataTableReader reader, string columnName)
{
// Consider when to use a procedure like this one carefully:
// if you're going to retrieve information from a column
// in a loop, it would be better to retrieve the column
// ordinal once, store the value, and use the methods
// of the DataTableReader class directly.
// Use this string-based indexer sparingly.
object columnValue = null;
try
{
columnValue = reader[columnName];
}
catch (ArgumentException ex)
{
// Throw all other errors back out to the caller.
columnValue = null;
}
return columnValue;
}
Private Function GetValueByName( _
ByVal reader As DataTableReader, _
ByVal columnName As String) As Object
' Consider when to use a procedure like this one carefully:
' If you're going to retrieve information from a column
' in a loop, it would be better to retrieve the column
' ordinal once, store the value, and use the methods
' of the DataTableReader class directly.
' Use Item(columnName) sparingly.
Dim columnValue As Object
Try
columnValue = reader.Item(columnName)
Catch ex As ArgumentException
' Throw all other errors back out to the caller.
columnValue = Nothing
End Try
Return columnValue
End Function
설명
대/소문자를 구분하는 조회가 먼저 수행됩니다. 실패하면 대/소문자를 구분하지 않는 두 번째 검색이 이루어집니다.
이 메서드는 가나 너비를 구분하지 않습니다.
이 오버로드된 버전은 Item[] 메서드를 호출 GetOrdinal 한 다음 메서드를 호출하는 데 해당합니다 GetValue .