Solved

wrong setting in ODBC-driver for Access ?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to remove Duplicates from Generic List in Csharp 5 75
C# page opens in new window 3 54
INNER JOIN ? 8 40
How to show result of a NULL value at random? 32 36
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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

929 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

13 Experts available now in Live!

Get 1:1 Help Now