Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

OleDBConection to worksheet sheet 1

$
0
0

The Following code reads in Sheet one from the Excel file when the Sheet name is EOM. Is there a way to read in sheet 1 with out specifying the sheet name ?

conn.Open();
            string con = null;
            if (fileType[1] == "xls" || fileType[1] == "xlsx")
            {
                con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + PollFolder + '\\' + fileName + @";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;ImportMixedTypes=MajorityType;TypeGuessRows=0""";
                using (OleDbConnection connection = new OleDbConnection(con))
                {
                    connection.Open();
                    OleDbCommand command = null;
                    command = new OleDbCommand
                   ("SELECT * " +"FROM [EOM$]", connection                   );
                    try
                    {
                        using (OleDbDataReader dr = command.ExecuteReader())
                        {
                            properFormat = 1;
                            while (dr.Read())
                            {


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>