0

i am developping a really simple program in c# with Visual studio, it consists simply by extracting data from an Excel sheet and transfer it to a database (only one table ), using MySql it worked i just saved the files as CSV and then imported them into my database but i had a big problem which was the encoding UTF8 i have many french characters ans arabic ones that just showed as random characters, so i went back to OleDb but it keeps shong exceptions now i am stuck with this one: System.Data.OleDb.OleDbException (0x80004005) i ve tried to change running config to x86 but nothing (notice that i am using a windows 8 X64). its a cummon ISAM problem.

please help me .

this is my code :

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 testoledb

{
    public partial class Form1 : Form
    {
        DataSet OleDs = new DataSet();
        OleDbDataAdapter OleAdapter = new OleDbDataAdapter();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }

        private void upload_excl_Click(object sender, EventArgs e)
        {
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            path = Path.Combine(path, "AGENDA.xlsx");

            string OleConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+path+@";Extend Properties=Excel 12.0 Macro;MDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0"; //,HDR=Yes;IMEX=1""";

            OleDbConnection OleConn = new OleDbConnection(OleConnectionString);

            string OleStrCmd = "select * from [SHeet1$A1:H330]";

            OleDbCommand OleCmd = new OleDbCommand(OleStrCmd, OleConn);

            try
            {
                OleConn.Open();
                OleDs.Clear();
                OleAdapter.SelectCommand = OleCmd;
                OleAdapter.Fill(OleDs);
                dataGridView1.DataSource = OleDs.Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
            finally
            {
                OleConn.Close();
            }
        }
    }
}
Aziz1989
  • 73
  • 2
  • 14
  • What is the error message? If it's "provider Microsoft.ACE.OLEDB... is not registered" then either you didn't set the process to 32-bit (or it was already 32-bit and you need to set it to 64-bit) or you don't have ACE installed. – ta.speot.is Jul 22 '14 at 10:21
  • --------------------------- --------------------------- System.Data.OleDb.OleDbException (0x80004005): Pilote ISAM introuvable. à System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) – Aziz1989 Jul 22 '14 at 10:28
  • According to http://stackoverflow.com/questions/8797978/how-to-resolve-could-not-find-installable-isam-error-for-ole-db-provider-mic you need to set `Extended Properties` to `Excel 12.0`. You're setting `Extend Properties`. – ta.speot.is Jul 22 '14 at 10:31
  • i just tried it but nothing ... still same exception – Aziz1989 Jul 22 '14 at 10:36
  • According to http://stackoverflow.com/questions/8797978/how-to-resolve-could-not-find-installable-isam-error-for-ole-db-provider-mic and http://www.connectionstrings.com/excel/ you need quotes for `Extended Properties`. – ta.speot.is Jul 22 '14 at 10:48
  • ok i ve changed it to this : string OleConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+path+@";Extended Properties='Excel 12.0 Macro;MDR=Yes;ImportMixedTypes=Text;TypeGuessRows=0'"; but the error just move to the sql querry i think because it is showing this error now : System.Data.OleDb.OleDbException (0x80040E37): Le moteur de base de données Microsoft Access n’a pas pu trouver l’objet AGENDA$A1:H330. – Aziz1989 Jul 22 '14 at 10:58
  • `AGENDA$A1:H330` or `Sheet1$A1:H330`? – ta.speot.is Jul 22 '14 at 11:11
  • oh sorry but even with SHeet$A1:H330 dosn't work i was trying to change the name of the SHeet with the name of the file but still the same – Aziz1989 Jul 22 '14 at 11:18
  • What's the sheet's name in Excel? – ta.speot.is Jul 22 '14 at 11:19
  • it was Feuil 1 -_- sorry guys for you precious time i am really ashamed of my self :p thank you Very much it worked thanks. you are great people. :) – Aziz1989 Jul 22 '14 at 11:25

0 Answers0