Click here to Skip to main content
15,897,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
There is an error at the following statement stating that "Syntax error at INSERT INTO statement". The code is at the below.


C#
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

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.
 
Share this answer
 
Comments
Maciej Los 7-Mar-13 17:08pm    
Good suggestion ;)
I see TDate field. It's probably DateTime field. To insert date into MS Access database, use query like this:
SQL
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[^]
 
Share this answer
 
v2

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