How do I get the following code to work for Excel 2010?

Michael Sterling
Michael Sterling used Ask the Experts™
on
for some reason i couldn't get the code (included below) to work for Microsoft Excel 2010. I had to save the spread sheet into a 97 - 2003 format and then it worked. how do i get this to work for microsoft excel 2010, just incase. or for 2007 for that matter? the error i got was "file not in expected format" which is pretty self explanatory but i'd still like to get it to function for the later versions of excel if possible...
protected void UpLoadFile_Click(object sender, EventArgs e)
    {
        System.Uri uri1 = new Uri(@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xlsx");
        Uri relativeUri = uri1.MakeRelativeUri(uri1);
        OleDbConnection _con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xls;Extended Properties=Excel 12.0");

        try
        {
            _con.Open();
            System.Data.DataTable _tab = new System.Data.DataTable();
            System.Data.DataTable _SheetTable = new System.Data.DataTable();
            _SheetTable = _con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            for (int Sheet = 0; Sheet < _SheetTable.Rows.Count; Sheet++)
            {
                OleDbCommand _com = new OleDbCommand("SELECT * FROM [" + _SheetTable.Rows[Sheet][2].ToString() + "]", _con);
                OleDbDataAdapter _dap = new OleDbDataAdapter(_com);

                _dap.Fill(_tab);

                string _Meesage = string.Empty;
                for (int x = 0; x < _tab.Rows.Count; x++)
                {
                    for (int y = 0; y < _tab.Columns.Count; y++)
                    {
                        _Meesage += _tab.Rows[x][y].ToString() + ",";

                    }
                    _Meesage += "\r\n";

                }
                string _FileName = _SheetTable.Rows[Sheet][2].ToString();
                _FileName = _FileName.Replace("$", "");
                //_log.SuccessLoggingFileExcel(_FileName, _Meesage, Desitnation);
            }
            // _log.SuccessLogging("UFL", "Mesage from the Success Logging From the user");  

            //return "Successessfully Parsed";

        }
        catch (Exception ex)
        {
            //Logging _lo = new Logging();
            //_log.LogErrorLog("Exception", ex);
        }
    }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial