2

I am importing excel sheet at runtime in my windows forms, adding some data into it through form. When I am inserting that data back it's giving:

syntax error in insert into statement

This is the query I'm using:

string qry = string.Format("Insert into [Sheet1$] (username,password) values('"+uname+"','"+pwd+"')");
4
  • Just a hynch, but does your data have a single quote in either uname or pwd? Commented Dec 19, 2012 at 4:16
  • check this link: csharp.net-informations.com/excel/csharp-excel-oledb-insert.htm hope this will help you.regards Commented Dec 19, 2012 at 4:18
  • make sure that your sheet name is "Sheet1" Commented Dec 19, 2012 at 5:13
  • Can you show more of your code? Specifically the connection string. Also, how is your Excel sheet structured? Commented Dec 19, 2012 at 5:20

2 Answers 2

3

Try this ie adding [] to columns :

string qry = string.Format("Insert into [Sheet1$] ([username],[password]) values('"+uname+"','"+pwd+"')");

also try without string.Format()

Sign up to request clarification or add additional context in comments.

Comments

0

The code was correct,there were permission issues with the excel file that i was using I wasnt having full control on that excel,I changed the permissions and the code started working.

1 Comment

So how come you said the other answer worked?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.