473,668 Members | 2,408 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 2273
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
2034
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
4188
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 Excel 2003, I have VBA code that creates and executes queries using the Access database, and returns the results to an Excel sheet. The first time the query is executed, results are returned to Excel in usually less than 10 seconds. However, if the...
1
2038
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 any other .mdb file, it works perfectly. 2. This is a Winform application, so no problems about the ASPNET wp being granted rights.
1
2339
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 Error: Line 196: for i = 0 to ubound(emaillist) Line 197: selectsqlstatement = "select * from tblusers where id =" & emaillist(i)
0
7710
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: "-2147467259 The database has been place in a state by user 'Admin' on machine ..... that prevents it from being opened or locked."
3
4995
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 it? I have tried "yes", "no", "true", "false", but i cant get it right e.g SQL = UPDATE Users SET Name = TRUE WHERE ID = 1 anyone got a clue?
4
15446
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, qty_x, qty_y, qty_z, qty_o ( code:ch, qty_x,qty_y, qty_z, qty_o : n) Table2: code, qty, xyz ( code:ch, qty: n, xyz=ch) Relationship created between the two tables on code field
2
1819
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 SumOfProv1.Volume is an invalid name. How do I get around this error. (note: the name is Prov1.Volume because the column name came from an inner join. Is there a way to rename this column and possibly thereby avoid the error? Sums of other columns work...
2
3717
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))) This fails. However, this also fails: CStr()
6
2784
by: D Rid | last post by:
here is my SQL statement: SELECT . , .* , .* FROM ( INNER JOIN ON . = CDBL(])) INNER JOIN
0
8462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8382
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7405
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

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.