Syntax error in INSERT INTO statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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)"\
<[email protected]>"

Thank you for your help in solving this problem.
 
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
 
That was it! Thank you, Thank you Ken.

Ken Kolda said:
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 said:
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)"\
<[email protected]>"

Thank you for your help in solving this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top