Jump to content

C# Reading Excel From an Excel File


Recommended Posts

Hi I recieve the following message at the line dr.Excel.Fill(dataSet1); dataSet1 is a dataSet object created in form1.

 

"The Microsoft Jet database engine could not find the object 'orders'.  Make sure the object exists and that you spell its name and the path name correctly."

 

Here is the source (assume windows open dialog works):

if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                m_fileLocation = openFileDialog1.FileName;
            }

            string theConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + m_fileLocation + ";Extended Properties='HTML Import;HDR=YES;IMEX=1;'";

		//
		// Open the spreadsheet and query the data.
		//
            OleDbConnection cnExcel = new OleDbConnection(theConnectionString);
            try
            {
                cnExcel.Open();
            }
            catch (OleDbException eee)
            {
                // catch (OleDbException eee)
                MessageBox.Show(eee.Message);
            }
            OleDbCommand cmdExcel = new OleDbCommand();
            cmdExcel.Connection = cnExcel;
            cmdExcel.CommandText = @"SELECT * FROM [orders]";

            OleDbDataAdapter drExcel = new OleDbDataAdapter();
            drExcel.SelectCommand = cmdExcel;
            drExcel.Fill(dataSet1);
		cnExcel.Close();

 

Anyone see what i am doing wrong? I think the problem occur is at : cmdExcel.CommandText = @"SELECT * FROM [orders]";

 

I have also tried cmdExcel.CommandText = @"SELECT * FROM [orders$]";

 

THANKS FOR THE HELP!!!  :)

Link to comment
https://forums.phpfreaks.com/topic/81643-c-reading-excel-from-an-excel-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.