i have a situation where i load a dataset with excel file. All the worksheet are loaded as datatable with the appropriate worksheet name as datatable name. What i am trying to do is get this datatable value using column name. But i am not get error saying
"Column 'Execute' does not belong to table Sheet1".
While loaded excel to datatabel i have used HDR=YES and IMEX=1. I also tried with HDR=NO. nothing is working.
below code is to write excel to datatable
foreach (Microsoft.Office.Interop.Excel.Worksheet wsheet in workbook.Worksheets)
{
string sql1 = "SELECT * FROM [" + wsheet.Name + "$]";
OleDbCommand selectCMD1 = new OleDbCommand(sql1, SQLConn);
SQLAdapter.SelectCommand = selectCMD1;
SQLAdapter.Fill(dataset.Tables.Add(wsheet.Name));
}
Data from excel loads to each sheet perfectly. but fetching it by column name is the problem.
any suggestions please
SQLDataAdapterand not theOleDbDataAdapter? I just tried your code but with theOleDbDataAdapterand it worked fine (i.e. I got column names).