You need to import data from the excel file into the datagridview, but it cannot find the file, although the path is correct. It gives an error: the object was not found by the microsoft office access database engine. Where is the mistake? Thanks in advance itself Excel http://imgur.com/W0ENhDF

using System.Data; using System.Threading.Tasks; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; using System.IO; using System.Reflection; using System.Data.OleDb; namespace WindowsFormsApplication5 { public partial class Form1 : Form { DataSet ds = new DataSet(); OleDbDataAdapter adapter = new OleDbDataAdapter(); public Form1() { InitializeComponent(); } private void Connection_Click(object sender, EventArgs e) { string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); MessageBox.Show(path.ToString()); path = Path.Combine(path, "textfortest.xlsx"); string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+path+@"; Extended Properties=""Excel 12.0 Macro;HDR=Yes;ImportMixedTypes=Text;TypeGuessRowsIMEX=1;TypeGuessRows=0"""; OleDbConnection conn = new OleDbConnection(ConnectionString); string Strcmd = "select * from [Лист1$A1:D9]"; OleDbCommand cmd = new OleDbCommand(Strcmd, conn); try { conn.Open(); ds.Clear(); adapter.SelectCommand = cmd; adapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { conn.Close(); } } } } 
  • Attach Trace - Senior Pomidor
  • @SeniorAutomator what is it? No experience yet) - Dmitry Ushkevich
  • stack trace- exception thrown by the program - Senior Pomidor

1 answer 1

Error message when you run a join query that contains more than one join for tables with complex data: "The object was not found by the Microsoft Office Access database engine"

When adding an attachment field to a table, the following error message may appear: {The object was not found by the Microsoft Office Access database engine. Check the existence of the object and the correctness of the name and path } This error occurs when a join request is found in the field that contains more than one join for tables with complex data.

Taken from here

ps I think that the problem in the names of the columns seems to be

  • column names in excel file? - Dmitry Ushkevich
  • @DmitryUshkevich yes, are there any spaces in the column names? - Senior Pomidor
  • checked for gaps, no gaps. The most common file, up to 5 columns imgur.com/W0ENhDF - Dmitry Ushkevich
  • @DmitryUshkevich see the answer to this question at stackoverflow.com/questions/951005/… Try to do the same - Senior Pomidor
  • thank you very much, I'll see now - Dmitry Ushkevich