473,508 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Syntax error in update query using ms access database and .net 4.0

1 New Member
Expand|Select|Wrap|Line Numbers
  1. private void update_Click(object sender, EventArgs e)
  2.         {
  3.             OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\shobhit\Documents\Environment_Monitoring.accdb;
  4. Jet OLEDB:Database Password=divya6");
  5.             String sdat = dateTimePicker1.Value.ToShortDateString();
  6.             String la = labs.SelectedItem.ToString();
  7.             String one = "EMI EMC Lab 3rd Floor";
  8.             String two = "Envrionment Lab 2nd Floor";
  9.             String three = "Electrical Performance Test Lab 3rd Floor";
  10.             String four = "Electrical Safety Test Lab 1(first floor)";
  11.             String five = "Electrical Safety Test Lab 2(ground floor)";
  12.             String six = "Electrical Safety Test Lab 3(ground floor)";
  13.             String seven = "Photometry Lab";
  14.             String eight = "Electrical General Lab";
  15.             String tempr = roomtemp.Text;
  16.             String humid = humidity.Text;
  17.             String ll = lightlevel.Text;
  18.             String ln = lnvolt.Text;
  19.             String ne = nevolt.Text;
  20.             String air = airpressure.Text;
  21.  
  22.             if (la.Equals(one))
  23.             {
  24.                 Console.WriteLine("hello");
  25.                 OleDbCommand cmmd = new OleDbCommand("UPDATE EMI_EMC_LAB SET ROOM_TEMPERATURE=@TEMP,HUMIDITY=@HUMID,LIGHT_LEVEL=@LL,L-N_VOLTAGE=@LN,N-E_VOLTAGE=@NE,AIR_PRESSURE=@AIR WHERE EDDATE=@SDAT", conn);
  26.                 cmmd.Parameters.Add("@SDAT", OleDbType.VarChar).Value = sdat;
  27.                 cmmd.Parameters.Add("@TEMPR", OleDbType.VarChar).Value = tempr;
  28.                 cmmd.Parameters.Add("@HUMID", OleDbType.VarChar).Value = humid;
  29.                 cmmd.Parameters.Add("@LL", OleDbType.VarChar).Value = ll;
  30.                 cmmd.Parameters.Add("@LN", OleDbType.VarChar).Value = ln;
  31.                 cmmd.Parameters.Add("@NE", OleDbType.VarChar).Value = ne;
  32.                 cmmd.Parameters.Add("@AIR", OleDbType.VarChar).Value = air;
  33.  
  34.                 conn.Open();
  35.                 int temp1 = cmmd.ExecuteNonQuery();
  36.                 if (temp1 > 0)
  37.                 {
  38.                     labs.Text = null;
  39.                     roomtemp.Text = null;
  40.                     humidity.Text = null;
  41.                     lightlevel.Text = null;
  42.                     lnvolt.Text = null;
  43.                     nevolt.Text = null;
  44.                     airpressure.Text = null;
  45.                     MessageBox.Show("Record Successfuly Added");
  46.                 }
  47.                 else
  48.                 {
  49.                     MessageBox.Show("Record Fail to Added");
  50.                 }
  51.                 conn.Close();
  52.             }
Feb 21 '14 #1
1 2266
Rabbit
12,516 Recognized Expert Moderator MVP
You have dashes in your field names. That is a non-standard character and it thinks you are trying to subtract 2 fields. You need to surround your field name with square brackets so it knows it is a field name and you are not trying to subtract. You should avoid using non-standard characters in field names.
Feb 21 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2021
by: sheree | last post by:
I have 3 tables (amoung a few others) in a small access database. The tables are as follows: == AEReport -------- AEID (PK) RptCatelog GCRCID PatientID EvntDate
0
4173
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS...
1
2026
by: maneeshkhare | last post by:
I am trying to update a field in Access db (.mdb) via a DataSet using the following code. I am continously getting this error: Has anybody seen this before? 1. If I try using the same code for...
1
2336
by: amitbadgi | last post by:
I am geting the following error while conv an asp to asp.net Exception Details: System.Runtime.InteropServices.COMException: Syntax error in query expression 'id =System.__ComObject'. Source...
0
7698
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
3
4983
by: Bonzol | last post by:
VB.net 2003, 1.1, webapplication hey there connecting to an Access database. There is a field in the database that is yes/no What do I pass in to the datbase to make it check the box, or uncheck...
4
15441
by: Kannan s | last post by:
Dear Sir, Sub: help requred to build an Update Query using if or iif I am having two tables with the following fields I wish to create a single update query in MS Access Table1: code,...
2
1812
by: Tom Baxter | last post by:
I have a numeric column in a query called Prov1.Volume. When I try taking the sum of that column (using SUM aggregate function in Design View) it gives a syntax error. It says that...
2
3710
by: midlothian | last post by:
Hello Trying to update a memo field in an update query using the Replace function, and am getting a type conversion error. Here is my parameter: CStr(Replace(CStr(),"$",Chr$(13) & Chr$(10))) ...
6
2765
by: D Rid | last post by:
here is my SQL statement: SELECT . , .* , .* FROM ( INNER JOIN ON . = CDBL(])) INNER JOIN
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.