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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.