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!

Re: OleDb Insert Query by Miha

Miha
Wed Aug 18 17:46:17 CDT 2004

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" <valentin.arkhipov@tiscali.co.uk> wrote in message
news:u5MmIEXhEHA.904@TK2MSFTNGP09.phx.gbl...
> 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!
>



Re: OleDb Insert Query by Val

Val
Fri Aug 20 13:52:52 CDT 2004

Thanks Miha,
Il try to code "normall" from now on, it will be a better world for everyone
:]


"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:%236HwsUXhEHA.3912@TK2MSFTNGP11.phx.gbl...
> 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" <valentin.arkhipov@tiscali.co.uk> wrote in message
> news:u5MmIEXhEHA.904@TK2MSFTNGP09.phx.gbl...
>> 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!
>>
>
>