Click here to Skip to main content
11,495,945 members (62,376 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 OleDb msaccss
There is an error at the following statement stating that "Syntax error at INSERT INTO statement". The code is at the below.


 OleDbComm.CommandText = @"INSERT INTO Full_Blood_Count ([PatID],[PatName],[PatAge],[PatAddress],
                                                                   [TDate],[TTime],[Hae],[Hae2],[Rbc],[Rbc2],
                                                                   [Pcv],[Pcv2],[Mcv],[Mcv2],[Mch],[Mch2],[Mchc],[Mchc2],
                                                                   [Plat],[Plat2],[Wbc],[Wbc2],[Neu],[Neu2],
                                                                   [Lym],[Lym2],[Eos],[Eos2],[Mono],[Mono2],
                                                                   [Bas],[Bas2],[RHae],[RRbc],[RPcv],[RMcv],[RMch],[RMchc]
                                                                   [RPlat],[RWbc],[RNeu],[RLym],[REos],[RMono],[RBas])VALUES 
                                                                                        ('" + strPatID + "','" + strPatName + "','" 
                                                                                            + strAge + "','" + strPatAdd + "','" 
                                                                                            + strTestDate + "','" + strTestTime + "','" 
                                                                                            + dblHaemo + "','" + strHae02 + "','" 
                                                                                            + dblRbc + "','" + strRbc02 + "','" 
                                                                                            + dblPcv + "','" + strPcv02 + "','" 
                                                                                            + dblMcv + "','" + strMcv02 + "','" 
                                                                                            + dblMch + "','" + strMch02 + "','" 
                                                                                            + dblMchc + "','"+ strMchc02 + "','" 
                                                                                            + dblPlat + "','"+ strPlat02 + "','" 
                                                                                            + dblWbc + "','" + strWbc02 + "','" 
                                                                                            + dblNeu + "','" + strNeu02 + "','" 
                                                                                            + dblLym + "','" + strLym02 + "','" 
                                                                                            + dblEos + "','" + strEos02 + "','" 
                                                                                            + dblMono + "','" + strMono02 + "','" 
                                                                                            + dblBas + "','" + strBas02 + "','"
                                                                                            + strRHae + "','"+ strRRbc +"','"
                                                                                            + strRPcv + "','" + strRMcv + "','"
                                                                                            + strRMch + "','" + strRMchc + "','"
                                                                                            + strRPlat + "','" + strRWbc + "','"
                                                                                            + strRNeu + "','" + strRLym + "','"
                                                                                            + strREos + "','" + strRMono + "','"
                                                                                            + strRBas + "')";


Please can anyone solve this!

Thank you
Chiranthaka
Posted 7-Mar-13 11:29am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Whooo, what for a statement! This is bad design.
I suppose, your parameters contain some characters that break the string. I suggest you rewrite it to use parameters. See following example: http://www.java2s.com/Code/CSharp/Database-ADO.net/PassparametertoOleDbCommand.htm[^]. Remember, there are no named parameters, onyl ?, so you have to watch the order carefully.
And make sure you have the same number of formal and actual values in the statement.
  Permalink  
Comments
Maciej Los at 7-Mar-13 17:08pm
   
Good suggestion ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I see TDate field. It's probably DateTime field. To insert date into MS Access database, use query like this:
INSERT INTO MyTable (IntField, CharField, DateField)
VALUES(1, "Text", #yyyy/MM/dd#)
But...
I recommend you to read these articles:
Using ADO.NET for beginners[^]
ADO.NET, the right way[^]
A Beginner's Tutorial for Understanding ADO.NET[^]
and
Overwview of ADO.NET[^]
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 692
1 CHill60 318
2 Sascha Lefèvre 235
3 RyanDev 230
4 _Asif_ 155
0 Sergey Alexandrovich Kryukov 10,372
1 OriginalGriff 8,871
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100