public DataTable ReadExcelData()
{
string strFilePath=@"D:\SampleFolder\Sample.xls";
DataTable dt=new DataTable();
string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties='Excel 8.0;HDR=Yes;'";
string strQuery = "select * from [Sheet1$] where ColumnName='No'";
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand(strQuery, connection);
using (OleDbDataAdapter dbAdapter = new OleDbDataAdapter())
{
dbAdapter.SelectCommand = command;
command.Connection = connection;
DataSet resultsDataSet = new DataSet();
{
dbAdapter.Fill(resultsDataSet);
dt = resultsDataSet.Tables[0];
}
}
}
return dt;
}
No comments:
Post a Comment