DataTableReader.GetSchemaTable 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DataTable 의 열 메타데이터를 설명하는 값을 반환합니다DataTableReader.
public:
override System::Data::DataTable ^ GetSchemaTable();
public override System.Data.DataTable GetSchemaTable();
override this.GetSchemaTable : unit -> System.Data.DataTable
Public Overrides Function GetSchemaTable () As DataTable
반환
열 메타데이터를 설명하는 A DataTable 입니다.
예외
DataTableReader 닫혀 있습니다.
예제
다음 콘솔 애플리케이션 예제에서는 지정된 열에 대한 스키마 정보를 검색합니다.
DisplaySchemaTableInfo 프로시저 내에서 DataTableReader 열DataTableReader의 서수 위치를 나타내는 정수와 프로시저를 전달하고 프로시저는 스키마 정보를 콘솔 창에 출력합니다.
private static void TestGetSchemaTable()
{
// Set up the data adapter, using information from
// the AdventureWorks sample database.
// Modify the SQL expression to retrieve
// data from a different table.
SqlDataAdapter adapter =
SetupDataAdapter("SELECT * FROM Sales.Customer");
// Fill the DataTable, retrieving all the schema information.
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
DataTable table = new DataTable();
adapter.Fill(table);
// Create the DataTableReader, and close it when done.
using (DataTableReader reader = new DataTableReader(table))
{
// Modify the column number to display information
// about a column other than column 0.
DisplaySchemaTableInfo(reader, 0);
}
Console.WriteLine();
Console.WriteLine("Press Enter to finish.");
Console.ReadLine();
}
private static void DisplaySchemaTableInfo(
DataTableReader reader, int ordinal)
{
// Given a DataTableReader, display schema
// information about a particular column.
try
{
DataTable schemaTable = reader.GetSchemaTable();
DataRow row = schemaTable.Rows[ordinal];
foreach (DataColumn col in schemaTable.Columns)
{
Console.WriteLine("{0}: {1}",
col.ColumnName, row[col.Ordinal]);
}
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine("{0} is an invalid column number.",
ordinal);
}
}
private static SqlDataAdapter SetupDataAdapter(String sqlString)
{
// Assuming all the default settings, create a
// SqlDataAdapter working with the AdventureWorks
// sample database that's available with
// SQL Server.
String connectionString =
"Data source=(local);initial catalog=AdventureWorks;" +
"Integrated Security=True";
return new SqlDataAdapter(sqlString, connectionString);
}
Private Sub TestGetSchemaTable()
' Set up the data adapter, using information from
' the AdventureWorks sample database.
' Modify the SQL expression to retrieve
' data from a different table.
Dim adapter As SqlDataAdapter = _
SetupDataAdapter("SELECT * FROM Sales.Customer")
' Fill the DataTable, retrieving all the schema information.
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim table As New DataTable
adapter.Fill(table)
' Create the DataTableReader, and close it when done.
Using reader As New DataTableReader(table)
' Modify the column number to display information
' about a column other than column 0.
DisplaySchemaTableInfo(reader, 0)
End Using
Console.WriteLine()
Console.WriteLine("Press Enter to finish.")
Console.ReadLine()
End Sub
Private Sub DisplaySchemaTableInfo( _
ByVal reader As DataTableReader, ByVal ordinal As Integer)
' Given a DataTableReader, display schema
' information about a particular column.
Try
Dim schemaTable As DataTable = reader.GetSchemaTable()
Dim row As DataRow = schemaTable.Rows(ordinal)
For Each col As DataColumn In schemaTable.Columns
Console.WriteLine("{0}: {1}", _
col.ColumnName, row(col.Ordinal))
Next
Catch ex As IndexOutOfRangeException
Console.WriteLine("{0} is an invalid column number.", _
ordinal)
End Try
End Sub
Private Function SetupDataAdapter( _
ByVal sqlString As String) As SqlDataAdapter
' Assuming all the default settings, create a SqlDataAdapter
' working with the AdventureWorks sample database that's
' available with SQL Server.
Dim connectionString As String = _
"Data Source=(local);" & _
"Initial Catalog=AdventureWorks;" & _
"Integrated Security=true"
Return New SqlDataAdapter(sqlString, connectionString)
End Function
설명
GetSchemaTable 메서드는 각 열에 대한 메타데이터를 다음 순서로 반환합니다.
| DataReader 열 | 설명 |
|---|---|
| ColumnName | 에 표시되는 열의 이름입니다 DataTable. |
| ColumnOrdinal | 열의 서수 |
| ColumnSize | -1(ColumnSize또는) 속성을 DataColumn 확인할 수 없거나 관련이 없으면 1이고, 그렇지 않으면 값을 포함하는 0 또는 양의 정수입니다 MaxLengthMaxLength. |
| NumericPrecision | 열 형식이 숫자 형식인 경우 열의 최대 전체 자릿수입니다. 열 형식이 숫자 데이터 형식이 아니면 null 값입니다. |
| NumericScale | 열 데이터 형식에 배율 구성 요소가 있는 경우 소수점 오른쪽의 숫자 수를 반환합니다. 그렇지 않으면 null 값을 반환합니다. |
| 데이터 유형 | 열의 기본 형식입니다. |
| ProviderType | 열의 데이터 형식 표시기입니다. 열의 데이터 형식이 행마다 다르면 이 값은 다음과 같습니다 Object. 이 열은 null 값을 포함할 수 없습니다. |
| IsLong |
true열의 데이터 형식이고 해당 MaxLength 속성이 String -1이면 입니다. 그렇지 않으면 false입니다. |
| AllowDBNull |
true열에 대해 AllowDbNull 제약 조건이 true로 설정된 경우 그렇지 않으면 . false |
| 읽기 전용 여부 |
true 열을 수정할 수 없는 경우 그렇지 않으면 false. |
| IsRowVersion |
false, 모든 열에 대해 |
| IsUnique |
true: 이 열의 두 행이 DataTable 같은 값을 가질 수 없습니다.
IsUnique 은 열이 키를 단독으로 나타내거나 이 열에만 적용되는 UNIQUE 형식의 제약 조건이 있는 경우 true가 됩니다.
false: 열에 중복 값이 DataTable포함될 수 있습니다. 이 열의 기본값은 .입니다 false. |
| IsKey |
true: 열은 함께 사용하여 행을 고유하게 식별하는 DataTable열 집합 중 하나입니다. 로 설정된 true 열 IsKey 집합은 에서 행DataTable을 고유하게 식별해야 합니다. 이 열 집합이 최소 열 집합이라는 요구 사항은 없습니다. 이 열 집합은 기본 키, 고유 제약 조건 또는 고유 인덱스에서 생성 DataTable 될 수 있습니다.
false: 열이 행을 고유하게 식별할 필요는 없습니다. 이 값은 true 열이 단일 또는 복합 기본 키에 참여하는 경우입니다. 그렇지 않으면 해당 값이 false. |
| IsAutoIncrement |
true: 열은 고정된 증분으로 새 행에 값을 할당합니다.
false: 열이 고정된 증분에서 새 행에 값을 할당하지 않습니다. 이 열의 기본값은 .입니다 false. |
| BaseCatalogName | 열이 포함된 데이터 저장소의 카탈로그 이름입니다.
Null 기본 카탈로그 이름을 확인할 수 없으면 입니다. 이 열의 기본값은 값입니다 null . |
| BaseSchemaName | 이 값은 항상 Null.입니다. |
| BaseTableName | DataTable의 이름입니다. |
| BaseColumnName | 에 있는 열의 이름입니다 DataTable. |
| AutoIncrementSeed | 's 속성의 DataTable값입니다 AutoIncrementSeed . |
| AutoIncrementStep | 's 속성의 DataTable값입니다 AutoIncrementStep . |
| 기본값 | 's 속성의 DataColumn값입니다 DefaultValue . |
| Expression | 현재 열이 식 열이고 식에 사용된 모든 열이 식 열이 포함된 열 T:System.Data.DataTable 에 속하는 경우 식 문자열이고, 그렇지 않으면 null식 문자열입니다. |
| ColumnMapping | 에 MappingType 연결된 값입니다 DataColumn. 형식은 , Element또는 HiddenSimpleContent. 중 Attribute하나일 수 있습니다. 기본값은 Element입니다. |
| BaseTableNamespace | 's 속성의 DataTable값입니다 Namespace . |
| BaseColumnNamespace | 's 속성의 DataColumn값입니다 Namespace . |