then you would need to get the data range into an Excel Range and iterate through it and construct the DataTable. There is no easy way out.
So, you need to append some pretty basic code around the Interop code that you have shown.
Like:
Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(@"c:\\TestBook1.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, false, Microsoft.Office.Interop.Excel.XlCorruptLoad.xlNormalLoad);
Microsoft.Office.Interop.Excel.Sheets sheets = theWorkbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
'If you are not sure of the range of data, use UsedRange, but make sure you handle the null values explicitly.
int columnCount = worksheet .UsedRange.Cells.Columns.Count;
int rowCount = worksheet .UsedRange.Cells.Rows.Count;
DataSet myDataSet = new DataSet();
DataTable myDataTable = new DataTable();
//Add the DataColumns to the DataTable.
for (int counter = 1; counter <= columnCount ; counter++)
{
myDataTable.Columns.Add(string.concat("specifythecolumnnamehere", counter.ToString()), System.Type.GetType("System.String"));
}
DataRow myDataRow;
Excel.Range range;
//Add the Rows to the DataTable.
for (int rowCounter = 1; rowCounter <= rowCount; rowCounter++)
{
myDataRow = myDataTable.NewRow();
for (int colCounter = 1; colCounter <= columnCount; colCounter ++)
{
range = (Microsoft.Office.Interop.Excel.Range) (worksheet.Cells[rowCounter, colCounter]);
myDataRow[string.concat("specifythecolumnnamehere", colCounter.ToString()) = range.Text;
}
myDataTable.Rows.Add(dr);
}
//Add the datatable to the DataSet.
myDataSet.Tables.Add(myDataTable);
However note that the OleDataAdapter method reads the used range from a WorkSheet into a DataSet directly , which is simpler if that is what you are after.