Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to insert data in MS Excel file to a specific rown and specific cell

But I am getting error in sql syntax.
Below is my C# Code

C#
OleDbCommand ocmd2 = new OleDbCommand("insert into [" + fileUpload.FileName + "] ([LATTITUDE], [LONGTITUDE]) values ('abc', '123') where [CLIENTS_ID]=42;", oconn);
ocmd2.ExecuteNonQuery();



[CLIENTS_ID] is the column name having IDs of data.
[LATTITUDE] and [LONGTITUDE] are the colums where I am entering the data.

I have tried both
C#
[CLIENTS_ID]=42
and
C#
[CLIENTS_ID]='42'

but I get
"Missing ; at the end of Sql Command"

Please help
Posted
Comments
Love 2 code 12-Sep-13 4:09am    
Hi,
an insert statement does not have a where clause, if you want to update existing data use an update statement like
UPDATE mytable SET LATTITUDE = 'abc', LONGITUDE = '123' WHERE CLIENTS_ID = 42;
Saqib Mobeen 12-Sep-13 4:59am    
ohhhh.....
thanks alot

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