Dynamically determining C# data types from empty Database tables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have sucessfully used Reader.GetSchemaTable() to dynamically discover C# types from populated database tables. However, I need to determine the C# data type for the columns of empty tables in order to populate them. I have attempted to use GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] {null, null, table.getTableName(), null}); However, the type returned in the schemaTable is a number and cannot be cased to a C# Type. In additions, I haven't discovered a way to map the number to the C# Type. Is there a way to predetermine the C# type or map the type number into the correct C# type.
 
Hi,

I don't think that there is a simple way (oledb doesn't know of .net
anyway).
I guess you'll have to do mapping yourself.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

FishNBrewDude said:
I have sucessfully used Reader.GetSchemaTable() to dynamically discover C#
types from populated database tables. However, I need to determine the C#
data type for the columns of empty tables in order to populate them. I have
attempted to use GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[]
{null, null, table.getTableName(), null}); However, the type returned in the
schemaTable is a number and cannot be cased to a C# Type. In additions, I
haven't discovered a way to map the number to the C# Type. Is there a way to
predetermine the C# type or map the type number into the correct C# type.
 
Actually I was able to do it with Reader.GetSchemaTable(). I discovered that I didn't need to read from the reader in order to call GetSchemaTable. In fact the where clause can always be false i.e where 1 = 0 and the function still works. Once I have the DataRow returned from getSchemaTable(), I can use the "DataType" column that returns the C# data type

Thanks
 
Back
Top