?
Solved

wrong setting in ODBC-driver for Access ?

Posted on 2001-06-15
5
Medium Priority
?
431 Views
Last Modified: 2012-06-21
In my asp-page, I want to send SQL commands containing an apostroph (') to an Access database.

e.g.:
INSERT INTO entries VALUES("myname","myname@aprovider","it's great ","6/15/2001")

These commands work fine when I execute them in Access itself, but I get an error (Too few parameters, expected 4) when I try to execute this command in my asp-page.

I had the same problem with a database made in MS SQL Server; and that could be solved by turning off the option "Use Ansi Quoted Strings" in the ODBC-driver for SQL Server, so I think the problem is in the ODBC-driver I use for Access.  I don't have any idea which option I have to change in the ODBC-driver for Access (I tried to change the option ExtendedAnsiSQL from 0 to 1, but that had no effect ...)

Any ideas ?

P.S. :  This is the piece of the asp code I use :

<% @language="JavaScript" %>
...
<%
var Connectie = Server.CreateObject("ADODB.Connection");
Connectie.Open("ODBC_guestbook");
var SQLstring = "INSERT INTO entries VALUES(\""+Request("naam")+"\",\""+Request("email")+"\",\""+Request("inhoud")+"\",\""+Request("pubdate")+"\")";
Response.write(SQLstring);
Connectie.Execute(SQLstring);
Connectie.Close();
%>
...
0
Comment
Question by:Ann_Van_Eyken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:weesiong
ID: 6194365
Ann_Van_eyken,

var SQLstring = "INSERT INTO entries VALUES(\""+Request("naam")+"\",\""+Request("email")+"\",\""+Request("inhoud")+"\",#""+Request("pubdate")+"#")";

Regards,
Wee Siong
0
 

Author Comment

by:Ann_Van_Eyken
ID: 6194403
The problem has nothing to do with the date format; it's really a problem of the ODBC driver with the apostrophs (') and quotation marks (") !

When I use

var SQLstring = "INSERT INTO entries VALUES('"+Request("naam")+"','"+Request("email")+"','"+Request("inhoud")+"','"+Request("pubdate")+"')";

it works fine, but then I can't use any apostroph in Request("naam", Request("inhoud"), etc.
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6194511
Ann_van_Eyken,

>it works fine, but then I can't use any apostroph in Request("naam", Request("inhoud"), etc.

I dont got your means, sorry, if it is single quote problem, you need replace it

Replace(Request("naam"),"'","''")

Regards,
Wee Siong
0
 

Author Comment

by:Ann_Van_Eyken
ID: 6194564
It's not (only) a single quote problem.

Suppose the user types

it's ok

in the text field with name inhoud.

In my asp code, I want to create dynamically the SQL command that inserts this value (it's ok), and also the values of other text fields, in my Access database.

Therefor, I use

var SQLstring = "INSERT INTO entries VALUES(\""+Request("naam")+"\",\""+Request("email")+"\",\""+Request("inhoud")+"\",\""+Request("pubdate")+"\")";

This works fine for MS SQL Server (after I've changed a setting in the configuration of the ODBC-driver, cfr. supra), but it doesn't work for Access.
Since the SQL command I create this way can be executed in Access directly (cfr. supra), I think it's something with the ODBC driver for Access ...
0
 
LVL 20

Accepted Solution

by:
Michel Sakr earned 300 total points
ID: 6194591
How do I deal with an apostrophe (') in a SQL statement?

This has got to be the most-often asked question in all three of these groups. The apostrophe is an illegal character in SQL because it is interpreted as a string delimiter. To allow a ' mark to be inserted into a database, simply double-up all occurences of the ' mark:
 
<%
    criteria = replace(criteria,"'","''")
%>
 
 
Inside the parentheses, for clarity, that's criteria,comma,quote,apostrophe,quote,comma,quote,apostrophe,apostrophe,quote (no spaces).
 
So, for the following...
 
<%
    mycrit = replace(mycrit,"'","''")
%>
 
 
...you may have statements like these:
 
<%
    sql = "insert into table(namefield) values('" & mycrit & "')"
%>
 
 
...or...
 
<%
    sql = "select namefield from table where namefield like '%" & mycrit & "%'"
%>

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question