Client Interfaces Guide > Connecting to TDV Server through ADO.NET > Sample Code for Testing of an ADO.NET Driver > Getting the Column Type
 
Getting the Column Type
This topic provides sample code showing how to get the column type.
To get the column type
1. Use the following sample code to get the column type:
public void TestColumnType()
{
CompositeConnection conn = GetConnection();
try
{
CompositeCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from products where ProductID=1111";
CompositeDataReader reader = cmd.ExecuteReader();
int columns = reader.FieldCount;
//reader.Read();
for (int i = 0; i < columns; i++)
{
Console.WriteLine("field name:" + reader.GetName(i) + ",field type:" + reader.GetFieldType(i));
}
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
 
The number of columns you can access is given by reader.FieldCount. If the value is 3, three columns are in the select result, so you can access columns 0, 1, and 2.
2. Call the GetName method to get the column name.
3. Call GetFieldType to get the column type.