473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Oledb Prameterized Query Question

59
Hi,
I am running the following code but it is giving an "Syntax error in insert statement" error
Considering detCon to be my connectionString.

Expand|Select|Wrap|Line Numbers
  1. OleDbCommand icmd = detCon.CreateCommand();
  2. icmd.CommandText = "insert into Details_Table (Account,Number) values (?,?)";
  3. OleDbParameter p1 = new OleDbParameter();
  4. OleDbParameter p2 = new OleDbParameter();
  5. icmd.Parameters.Add(p1);
  6. icmd.Parameters.Add(p2);
  7. p1.Value = "2";
  8. p2.Value = "3";
  9. detCon.Open();
  10. icmd.ExecuteNonQuery();
However if I run the same code for a single parameter i.e.

Expand|Select|Wrap|Line Numbers
  1. OleDbCommand icmd = detCon.CreateCommand();
  2. icmd.CommandText = "insert into Details_Table (Account) values (?)";
  3. OleDbParameter p1 = new OleDbParameter();
  4. icmd.Parameters.Add(p1);
  5. p1.Value = "2";
  6. detCon.Open();
  7. icmd.ExecuteNonQuery();
Its Working!
Can someone please point out my mistake??

Regards,
Sid
Sep 12 '08 #1
1 1057
babai28
59
Hi,
I found out the problem! The columns names to be included in square brackets for string type variables:

Expand|Select|Wrap|Line Numbers
  1. OleDbCommand icmd = detCon.CreateCommand();
  2. icmd.CommandText = "insert into Details_Table ([Account],[Number]) values (?,?)";
  3. OleDbParameter p1 = new OleDbParameter();
  4. OleDbParameter p2 = new OleDbParameter();
  5. icmd.Parameters.Add(p1);
  6. icmd.Parameters.Add(p2);
  7. p1.Value = "2";
  8. p2.Value = "3";
  9. detCon.Open();
  10. icmd.ExecuteNonQuery();
Thanks if anybody read this.

Regards,
Sid
Sep 12 '08 #2

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

Similar topics

14
by: | last post by:
Hi, I was performing SQL UPDATE queries and I notice that they SUCCEED on the ExecuteNonQuery() call with NO exceptions raised BUT they fail at the Database. They say they succeed in the code...
0
by: silesius | last post by:
I've been using VS 2003 to develop a webapplication using C#. Today I exported the application to a remote webserver I begun experiencing problems. It's a simple application that retrieves some...
2
by: VMI | last post by:
In Access, I can create a query like "select * from myTable where Name like '*Joe #*' " and it'll return records like ("Bob Joe 1", "Rick Joe 122", etc...). What's the equivalent to that in a...
1
by: Brian Henry | last post by:
I have an access database, and one of the fields in the table I am inserting into has a date/time data type. What is the correct OleDb data type to insert the date and time that it is at the moment...
0
by: silesius | last post by:
I've been using VS.NET 2003 to develop a webapplication using C#. Today I exported the application to another webserver I begun experiencing problems. It's a simple application that retrieves...
3
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I...
2
by: Martin | last post by:
Hi, I currently have an application that connects to an MS ACCESS database. This application uses an OLEDB connection string for MS ACCESS. Now, I'd like to upsize the application so I converted...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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...
0
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...
0
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,...
0
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...

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.