Solved

wrong setting in ODBC-driver for Access ?

Posted on 2001-06-15
5
425 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grab data from remote page 10 64
show region if a selection is made on a drop down menu 3 61
SP to delete duplicates 15 70
XML Parsing Classic ASP 5 56
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 information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now