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
Solved

wrong setting in ODBC-driver for Access ?

Posted on 2001-06-15
5
426 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
  • 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:
Silvers5 earned 100 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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