Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:28:09+00:00 2026-06-15T17:28:09+00:00

OpenFileDialog ofImport = new OpenFileDialog(); ofImport.Title = Select file; ofImport.InitialDirectory = @c:\; ofImport.FileName =

  • 0
OpenFileDialog ofImport = new OpenFileDialog();
ofImport.Title = "Select file";
ofImport.InitialDirectory = @"c:\";
ofImport.FileName = txtFileName.Text;
ofImport.Filter = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*";
ofImport.FilterIndex = 1;
ofImport.RestoreDirectory = true;

if (ofImport.ShowDialog() == DialogResult.OK)
{

     string path = System.IO.Path.GetFullPath(ofImport.FileName);
     string query = "SELECT * FROM Customer.xlsx";
     OleDbConnection conn = new OleDbConnection();
     conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ofImport.FileName+";Extended Properties=" + "\"Excel 12.0 Xml;HDR=YES;IMEX=1\"";
     OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);

     //DataSet dataSet = new DataSet();
     adapter.Fill(dsSource);
     dataGridView1.DataSource = dsSource;

}
else
{
     ofImport.Dispose();
}   

I want to retrive Excel data to the DataGridView using dataset. dsSource is the dataset used.

The Error I’m obtaing is on the line adapter.Fill(dsSource);:

The Microsoft Access database engine could not find the object ‘xlsx’.
Make sure the object exists and that you spell its name and the path
name correctly. If ‘xlsx’ is not a local object, check your network
connection or contact the server administrator.

I’m able to select the file but it is not Filling in dataset.

What to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:28:09+00:00Added an answer on June 15, 2026 at 5:28 pm
        DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
        if (dialogResult == DialogResult.Yes)
        {
            dt = dsSource.Tables[Index];
            dt.Reset();
            Excel.Workbook workbook;
            Excel.Worksheet NwSheet;
            Excel.Range ShtRange;
            Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application();
            OpenFileDialog filedlgExcel = new OpenFileDialog();
            filedlgExcel.Title = "Select file";
            filedlgExcel.InitialDirectory = @"c:\";
            //filedlgExcel.FileName = textBox1.Text;
            filedlgExcel.Filter = "Excel Sheet(*.xlsx)|*.xlsx|All Files(*.*)|*.*";
            filedlgExcel.FilterIndex = 1;
            filedlgExcel.RestoreDirectory = true;
            if (filedlgExcel.ShowDialog() == DialogResult.OK)
            {
    
                workbook = ExcelObj.Workbooks.Open(filedlgExcel.FileName, Missing.Value, Missing.Value,
                     Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                     Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                NwSheet = (Excel.Worksheet)workbook.Sheets.get_Item(1);
                ShtRange = NwSheet.UsedRange;
                for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                {
                    dt.Columns.Add(new DataColumn((ShtRange.Cells[1, Cnum] as Excel.Range).Value2.ToString()));
                }
                dt.AcceptChanges();
                string[] columnNames = new String[dt.Columns.Count];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    columnNames[0] = dt.Columns[i].ColumnName;
                }
                //string[] columnNames = (from dc in dt.Columns.Cast<DataColumn>() select dc.ColumnName).ToArray();
    
    
                for (int Rnum = 2; Rnum <= ShtRange.Rows.Count; Rnum++)
                {
                    DataRow dr = dt.NewRow();
                    for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                    {
                        if ((ShtRange.Cells[Rnum, Cnum] as Excel.Range).Value2 != null)
                        {
                            dr[Cnum - 1] = (ShtRange.Cells[Rnum, Cnum] as Excel.Range).Value2.ToString();
                        }
                    }
                    dt.Rows.Add(dr);
                    dt.AcceptChanges();
                }
                workbook.Close(true, Missing.Value, Missing.Value);
                ExcelObj.Quit();
    
                dataGridView1.DataSource = dt;  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = Document; // Default file name dlg.DefaultExt =
var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = (*.JPG;*.GIF)|*.JPG;*.GIF; dlg.ShowDialog(); if (string.IsNullOrEmpty(dlg.FileName)) return; var fs
var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = (*.JPG;*.GIF)|*.JPG;*.GIF; dlg.ShowDialog(); if (string.IsNullOrEmpty(dlg.FileName)) return; var fs
using (var openFileDialog1 = new OpenFileDialog()) { openFileDialog1.Reset(); if (!string.IsNullOrEmpty(ExcelFilePath)) { string fileName =
public byte[] imageToByteArray(System.Drawing.Image imageIn) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.FileName = Document; //
I am reading from a text file line by line. StreamReader reader = new
I have successfully prompted user to select a file in C# using the openFileDialog
public void EncryptFile() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = JPEG Files (*.jpeg)|*.jpeg|PNG
I am creating a OpenFileDialog with filter like this: OpenFileDialog lfDialog = new OpenFileDialog();
i use an openFileDialog to read from a text file and print the values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.