Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I am truing to insert data to MS Access Database Table using oledb 4.0 I found an error

The statement



C#
private void btnPrint_Click(object sender, EventArgs e)
        {
 
            //Creating the Patient ID.
            intYear = DateTime.Now.Month;
            strYear = intYear.ToString();
            strID = cmbPatID.Text;
            strPatID = strYear + strID;

            //Creating the Patient Name.
            strName = txtPatName.Text;
            strTitle = cmbTitle.Text;
            strPatName = strTitle + strName;

            //Assigning Patient Age, Address.
            strAge = txtAge.Text;
            strPatAdd = txtAddress.Text;

            //Assigning other string variables.
            strHae02 = txtHae02.Text; strRbc02 = txtRbc02.Text; strPcv02 = txtPcv02.Text; strMcv02 = txtMcv02.Text; 
            strMch02 = txtMch02.Text; strMchc02 = txtMchc02.Text; strPlat02 = txtPlat02.Text; strWbc02 = txtWbc02.Text;
            strNeu02 = txtNeu02.Text; strLym02 = txtLym02.Text; strEos02 = txtEos02.Text; strMono02 = txtMono02.Text;
            strBas02 = txtBas02.Text; 

            //Assigning the Test Date & Test Time.
            strTestDate = tDate.ToString();
            strTestTime = tTime.ToString();

OleDbComm.Connection = OleDbConn;
            OleDbComm.CommandType = CommandType.Text;
            OleDbComm.CommandText = @"INSERT INTO Full_Blood_Count ([PatID],[PatName],[PatAge],[PatAddress],[TDate],[TTime],[Hae],[Hae2],[Rbc],[Rbc2],[Pcv],[Pcv2],[Mcv],[Mcv2],[Mchc],[Mchc2],[Plat],[Plat2],[Wbc],[Wbc2],[Neu],[Neu2],[Lym],[Lym2],[Eos],[Eos2],[Mono],[Mono2],[Bas],[Bas2]) 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 + "')";

            OleDbComm.ExecuteNonQuery();
            OleDbConn.Close();              


I got the error at
C#
OleDbComm.ExecuteNonQuery();


The error is

C#
System.Data.OleDb.OleDbException was unhandled
  Message="Syntax error (missing operator) in query expression ''*,'45','*','45','','5','*','5','*','5','*','5','*','5','*','5','*','5','*','5',' ','5','*','5','*')'."
  Source="Microsoft JET Database Engine"
  ErrorCode=-2147217900
  StackTrace:
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
       at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
       at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
       at Lanka_Lab.frmFulBldCuntDet.btnPrint_Click(Object sender, EventArgs e) in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\Lanka_Lab\Lanka_Lab\Form1.cs:line 831
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Lanka_Lab.Program.Main() in C:\Users\Administrator\Documents\Visual Studio 2008\Projects\Lanka_Lab\Lanka_Lab\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 


I cannot understand what is the error meaning

If someone can please solve this problem

Thank You!
Posted

1 solution

problrm is in oleDbCommand .at time of value insert..one ' is missing in query
try this
OleDbComm.CommandText = @"INSERT INTO Full_Blood_Count ([PatID],[PatName],[PatAge],[PatAddress],[TDate],[TTime],[Hae],[Hae2],[Rbc],[Rbc2],[Pcv],[Pcv2],[Mcv],[Mcv2],[Mchc],[Mchc2],[Plat],[Plat2],[Wbc],[Wbc2],[Neu],[Neu2],[Lym],[Lym2],[Eos],[Eos2],[Mono],[Mono2],[Bas],[Bas2]) 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 + "')";

hope it will help
 
Share this answer
 
Comments
Chiranthaka Sampath 7-Mar-13 1:13am    
Ok that made my problem solved Thanks for the help!

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