I am trying to return the list of columns names from a DataSet in C# based on an Excel Query I have performed. I am ok doing this (well I think), see code below. However, three of my column headings are Dates and the column name is displayed as F4, F5, F6. I have looked further and found that the Type (.getType) report System.Double but I am unable to convert them.
Sample file is:
UID | FirstName | Surname | 31/07/2010 | 31/08/2010
100 | test | test | 8.8 | 9.9
200 | test2 | test2 | 7.7 | 6.6
My output is:
UID
FirstName
System.String
Surname
System.String
F4
System.Double
F5
System.Double
F6
System.Double
Could you shed any light on this?
conn = new OleDbConnection(conStr);
conn.Open();
dbCmd = new OleDbCommand("SELECT * FROM [" + worksheetName + "$]", conn);
dbCmd.CommandType = CommandType.Text;
dbAd = new OleDbDataAdapter(dbCmd);
dbAd.Fill(ds);
foreach (DataTable table in ds.Tables)
{
foreach (DataColumn col in table.Columns)
{
Console.WriteLine(col.ColumnName);
Console.WriteLine(col.ToString());
Console.WriteLine(col.DataType);
//object t = col;
//Double ttd = (Double)t;
//Console.WriteLine(t);
}
}
I have searched high and low, but cannot find how to do this. I really don't want to read the file in use Excel Object Model as this is so slow.