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 Answer