OleDb Insert Query

  • Thread starter Thread starter Val
  • Start date Start date
V

Val

Hi all,
Having a lil problem with the OleDbConnection + Command.
The whole thing is done im c# and uses Access datbase, it builds a SQL
string from stuff that user typed in
then calls OleDbCommand.ExecuteNonQuery with the folowing string.

"INSERT INTO Trans (rID, [Number], Price, [Date], Month, Year, [Percent])
VALUES (6,1,5.95,18,8,2004,100)"

at which time the try-catch wraping comes up with an error "Synatx error in
INSERT INTO statement".
I have tryed putting that string directly into MS Office Access and it
executes perfectly......so wheres the problem?

Thank you!
 
Hi Val,

Doing it this way can give you a headache.
For beginning embed Month and Year with square brackets.
Then replace the values in sql string with parameters (? mark)
Then add necessary parameters to command instance (see ado.net help topics)
Then set the parameter values and it should be far more stable and region
settings friendly :-)
 
Thanks Miha,
Il try to code "normall" from now on, it will be a better world for everyone
:]


Miha Markic said:
Hi Val,

Doing it this way can give you a headache.
For beginning embed Month and Year with square brackets.
Then replace the values in sql string with parameters (? mark)
Then add necessary parameters to command instance (see ado.net help
topics)
Then set the parameter values and it should be far more stable and region
settings friendly :-)

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Val said:
Hi all,
Having a lil problem with the OleDbConnection + Command.
The whole thing is done im c# and uses Access datbase, it builds a SQL
string from stuff that user typed in
then calls OleDbCommand.ExecuteNonQuery with the folowing string.

"INSERT INTO Trans (rID, [Number], Price, [Date], Month, Year, [Percent])
VALUES (6,1,5.95,18,8,2004,100)"

at which time the try-catch wraping comes up with an error "Synatx error
in INSERT INTO statement".
I have tryed putting that string directly into MS Office Access and it
executes perfectly......so wheres the problem?

Thank you!
 
Back
Top