Created
May 6, 2014 07:00
-
-
Save abhi1010/36ecc206fc5f61f4b4bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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