Click here to Skip to main content
15,662,426 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am Simone and have a problem using oledb in c#:

I have to insert values from textboxes in a new row in a excel table.
here is the code:

private void scriviexcel(string filexcel)//fileexcel="c:\\prova.xls";
            string scheda="table1";
            OleDbConnection conn = new OleDbConnection();
            OleDbCommand command = new OleDbCommand();
            conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filexcel + ";Extended Properties=Excel 8.0;");//HDR=YES;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";
            string datao = DateTime.Now.ToString();
            datao=datao.Substring(0, 10);
            //cut the time from DateTime so datao="02/11/2011";
            string pro = "INSERT INTO " + scheda + "(nome,indirizzo,telefono,difetto,data) VALUES('{" + textBox1.Text + "}','{" + textBox2.Text + "}','{" + textBox3.Text + "}','{" + textBox4.Text + "}','{"+datao+"}')";
            command = new OleDbCommand

and this is the error:
"The Jet database engine could not find the object 'table1'. Make sure the object exists and the name and path name correctly."

I need to have microsoft office installed ?

can anyone help me?

Updated 17-Nov-11 8:43am

Share this answer
simo_dany 2-Nov-11 16:18pm    
thanks but still doesn't work.
Answer is in your question it self, are you trying to insert into Table1, check whether Excel file has Table1 workbook or [Sheet1$].

Even if it is Table1, you have to refer as [Table1$] which is referring to workbook.

Search on Google there are lot of code available for Excel including Excel APIs and oleDB.

Share this answer

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