Solved

wrong setting in ODBC-driver for Access ?

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

762 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

19 Experts available now in Live!

Get 1:1 Help Now