Click here to Skip to main content
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 George Jonsson 175
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2014
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