473,406 Members | 2,867 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,406 software developers and data experts.

Syntax error in INSERT INTO statement

This is my first time posting here and I'm also relatively new to the .NET
environment.

I am inserting a string into a Microsoft Access Database. I get an error
because of the string format. I've researched escape characters and
parameterized sql statements and am still unable to come up with an answer.
Please help, here is my block of code...

OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (From) VALUES
(?)", odbcConnection1);
int cmdresults;
myCommand.Parameters.Add("", OdbcType.Text).Value=q;
odbcConnection1.Open();
cmdresults = myCommand.ExecuteNonQuery();
odbcConnection1.Close();

The string q is a variable that contains any number of questionable
characters. An example would be "From: \"(Boggie)"\
<my************@emailaddress.com>"

Thank you for your help in solving this problem.
Nov 16 '05 #1
2 6248
I believe the problem is with your column name -- "From" is a SQL keyword.
Trying enclosing it in square brackets, e.g.

INSERT INTO Listgroup ([From]) VALUES (?)

Ken
"Boggie" <Bo****@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
This is my first time posting here and I'm also relatively new to the .NET
environment.

I am inserting a string into a Microsoft Access Database. I get an error
because of the string format. I've researched escape characters and
parameterized sql statements and am still unable to come up with an answer. Please help, here is my block of code...

OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (From) VALUES (?)", odbcConnection1);
int cmdresults;
myCommand.Parameters.Add("", OdbcType.Text).Value=q;
odbcConnection1.Open();
cmdresults = myCommand.ExecuteNonQuery();
odbcConnection1.Close();

The string q is a variable that contains any number of questionable
characters. An example would be "From: \"(Boggie)"\
<my************@emailaddress.com>"

Thank you for your help in solving this problem.

Nov 16 '05 #2
That was it! Thank you, Thank you Ken.

"Ken Kolda" wrote:
I believe the problem is with your column name -- "From" is a SQL keyword.
Trying enclosing it in square brackets, e.g.

INSERT INTO Listgroup ([From]) VALUES (?)

Ken
"Boggie" <Bo****@discussions.microsoft.com> wrote in message
news:0B**********************************@microsof t.com...
This is my first time posting here and I'm also relatively new to the .NET
environment.

I am inserting a string into a Microsoft Access Database. I get an error
because of the string format. I've researched escape characters and
parameterized sql statements and am still unable to come up with an

answer.
Please help, here is my block of code...

OdbcCommand myCommand = new OdbcCommand("INSERT INTO Listgroup (From)

VALUES
(?)", odbcConnection1);
int cmdresults;
myCommand.Parameters.Add("", OdbcType.Text).Value=q;
odbcConnection1.Open();
cmdresults = myCommand.ExecuteNonQuery();
odbcConnection1.Close();

The string q is a variable that contains any number of questionable
characters. An example would be "From: \"(Boggie)"\
<my************@emailaddress.com>"

Thank you for your help in solving this problem.


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gérard Leclercq | last post by:
ACCESS First fields are TEXT, last 2 are Numbers The name of the fields are correct. Dim MyConn Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
3
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the...
6
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
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.