Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I used following code to insert record to foxpro dbf. But it throws an exception "Command contains unrecognized phrase/keyword." How can I fixed this.

string strLogConnectionString = @"Provider=vfpoledb;Data Source=E:\DBF\fLog.dbf;Collating Sequence=machine;Mode=ReadWrite;";

OleDbConnection strConLog = new OleDbConnection(strLogConnectionString);
strConLog.Open();

OleDbCommand oComm = new OleDbCommand("Insert into flog(File,Status,LogTime) values('"+strFiles+"','"+strDesc+"','"+dDatetime+"')", strConLog);

oComm.ExecuteNonQuery();
Posted
Updated 28-Dec-10 0:11am
v2

I think you already got many answers from HERE[^].
 
Share this answer
 
Comments
Sanyon_d 28-Dec-10 6:19am    
I couldn't get any correct answer from any.
Are all the fields in your table strings? Is dDateTime a string?
Just a question.

Cheers
 
Share this answer
 
Comments
Sanyon_d 28-Dec-10 22:12pm    
dDateTime is a date time value. Others are strings.
 
Share this answer
 
Comments
Sanyon_d 28-Dec-10 22:13pm    
The problem here is when I'm using variables in the insert statement. If I just use string values('ss') without using the varibles for values, it works nice.
Do any of the values in the variables strFiles, strDesc, or dDateTime contain apostrophes? If they do, you're winding up with that apostrophe terminating your string and the rest of your query winds up as garbage (or worse). In that case you'll need to escape them (by doubling them, if memory serves). Either that or build a parameterized command.
 
Share this answer
 
Comments
Sanyon_d 28-Dec-10 22:13pm    
The problem here is when I'm using variables in the insert statement. If I just use string values('ss') without using the varibles for values, it works nice.
Marc A. Brown 28-Dec-10 22:18pm    
Ok, so again, look at the values you're trying to insert. What values are in those variables?
Try wrapping your datetime fields in curly braces instead of single quotes. Example: {12/28/2010}
 
Share this answer
 
Comments
Sanyon_d 28-Dec-10 22:13pm    
The problem here is when I'm using variables in the insert statement. If I just use string values('ss') without using the varibles for values, it works nice.

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