Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created a simple windows form application where i have created an excel file to store and retrieve data from. But while saving the data I am getting an erorr message...

Mycode:
C#
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                OleDbCommand cmd = new OleDbCommand();
                string query = null;
                connect = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data Source='c:\\mydemo.xlsx';Extended properties=Excel 8.0;");
                connect.Open();
                cmd.Connection = connect;
                query = "Insert into [Sheet1$] (software_name,versions,keys) values('" + txtSNmae.Text + "','" + txtVersion.Text + "','" + txtKey.Text + "')";
                cmd.CommandText = query;
                cmd.ExecuteNonQuery();
                connect.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        
    }
}


Please Help....
Posted
Comments
Herman<T>.Instance 12-May-14 14:52pm    
and what is the message?
DevParashar 13-May-14 2:09am    
The error is as follows:
(
System.Data.OleDb.OleDbException: Could not finf installable ISAM. at System.Data.OleDb.OleDbConnectionInternal..ctor(OnleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb
ZurdoDev 12-May-14 15:09pm    
You must understand that there is more than one possible error message. Please update your question with the error.

1 solution

My guess:
The connection string is wrong! Proper connection string[^] for *xlsx files is:
C#
connect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=c:\mydemo.xlsx;Extended properties='Excel 12.0;HDR=YES';");



For further information, please see:
Accessing Microsoft Office Data from .NET Applications[^]
 
Share this answer
 
v2
Comments
[no name] 12-May-14 15:28pm    
Good guess
Maciej Los 12-May-14 15:29pm    
Thank you, Wes ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900