>What .NET version are you using?
>With my version - 4.5 - the table created by GetSchemaTable has a string column called DataTypeName.
>I don't see any DataType column.
>
>
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getschematable.aspxWhere used to be ability to add comment to Help topic - I don't see it anymore :(
In any case, who should I now speak with about this problem. Why did they remove that useful property????? Now how I am supposed to get the .NET type using this code?
UPDATE. I found that this works
Console.WriteLine("Column type: {0}", rdr.GetFieldType((int)r["ColumnOrdinal"]));
but it is quite complex.
using (SqlDataReader sqlDataReader = command.ExecuteReader(CommandBehavior.SchemaOnly))
{
DataTable tbl = sqlDataReader.GetSchemaTable();
foreach (DataRow r in tbl.Rows)
{
ColumnSchema colSchema = new ColumnSchema();
String readerColumnName = r["ColumnName"].ToString();
colSchema.ColumnName = readerColumnName;
colSchema.ColumnSize = r.Field<Int16>("ColumnSize");
colSchema.DataType = (Type)(r["DataType"]);
colSchema.DbType = (SqlDbType)(Convert.ToInt32(r["ProviderType"]));
columnTypes.Add(readerColumnName, colSchema);
}
TableSchema schema = new TableSchema(tableName, columnTypes);
tableSchema.Add(tableName, schema);
}
If it's not broken, fix it until it is.
My Blog