string strFilePath = this.MapPath(".") + "\\Workbook.xls";
string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
System.Data.OleDb.OleDbConnection cnCSV = new System.Data.OleDb.OleDbConnection(strConnectionString);
cnCSV.Open();
System.Data.OleDb.OleDbCommand cmdselect = new System.Data.OleDb.OleDbCommand();
if (true)
{
cmdselect.CommandText = "SELECT * FROM [Sheet1$A1:C6]";
cmdselect.Connection = cnCSV;
}
System.Data.OleDb.OleDbDataAdapter daCSV = new System.Data.OleDb.OleDbDataAdapter();
daCSV.SelectCommand = cmdselect;
DataTable dtCSV = new DataTable();
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
The code above should read in an excel file into ur datatable. You will have to change the select command for your purposes.