Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created May 6, 2014 07:00
Show Gist options
  • Save abhi1010/36ecc206fc5f61f4b4bc to your computer and use it in GitHub Desktop.
Save abhi1010/36ecc206fc5f61f4b4bc to your computer and use it in GitHub Desktop.
public IEnumerable<OdbcDataReader> ReadFile(string strExcelPath, string strWorkSheetName)
{
OdbcConnection connODBC = new OdbcConnection("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=" + strExcelPath + ";DefaultDir=c:\\;");
OdbcDataReader readerODBC = null;
connODBC.Open();
OdbcCommand commandODBC = new OdbcCommand("select * from [" + strWorkSheetName + "$]", connODBC);
readerODBC = commandODBC.ExecuteReader();
while (readerODBC.Read())
{
yield return readerODBC;
}
if (readerODBC != null)
{
readerODBC.Close();
readerODBC.Dispose();
}
connODBC.Close();
connODBC.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment