Getting a weird error code when I run my program

  • Thread starter Thread starter Jarvan IV
  • Start date Start date
J

Jarvan IV

Guest
system.invalidOperationException: The Microsoft.ACE.OLEDB.12.0 Provider (Its a long error code and I cant post a picture hopefully that is enough.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Excel = Microsoft.Office.Interop.Excel;

using System.Reflection;
using System.IO;
using System.Data.OleDb;


namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{

DataSet ds = new DataSet();
OleDbDataAdapter adapter = new OleDbDataAdapter();
public Form1()
{
InitializeComponent();
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
path = Path.Combine(path, "Book1.xlsm");

string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path
+ @";Extended Properties=""Excel 12.0 Macro; HDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0""";

OleDbConnection conn = new OleDbConnection(ConnectionString);

string strcmd = "select * from [Sheet 1$A1:D13]";
//May need to change the sheet info, depends on size of SQD

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();
}
}
}
}



Ive only done the "Get info button" and the DB

Can someone tell me what im doing wrong?

This is C#

Continue reading...
 
Back
Top