Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2003, 07:48 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO Update "Variable not found "

I am trying to insert into a visual foxpro database with the following code:


<%@ LANGUAGE = JavaScript%>
<%
var adoConnection = Server.CreateObject("ADODB.Connection");

var constring = "Provider=VFPOLEDB.1;Data Source=D:\\test\\test.dbc";

adoConnection.Open(constring);
var today

today = "12/12/2003";

adoConnection.Execute("INSERT INTO table1 (date) VALUES(today)");

adoRecordSet.Close();
adoRecordSet = null;
adoConnection.Close();
adoConnection = null;
%>

Apparently the variable is not being seen by the command. What am I doing wrong???????????????

I receive the following error message when running the script.

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Technical Information (for support personnel)
· Error Type:
Microsoft OLE DB Provider for Visual FoxPro (0x80004005)
Variable 'TODAY' is not found.
/counter2.asp, line 12
· Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; AT&T CSM7.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
· Page:
GET /counter2.asp
· Time:
Sunday, November 30, 2003, 1:57:04 PM
· More information:



 
Old December 1st, 2003, 12:39 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

"today" is buried inside the command string. You need to insert the actual value.

adoConnection.Execute("INSERT INTO table1 (date) VALUES('"+today+"')");

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 1st, 2003, 09:09 AM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sounded good but in practice I receive another runtime error

Error Type:
Microsoft JScript compilation (0x800A03EE)
Expected ')'
/counter2.asp, line 12, column 57
adoConnection.Execute("INSERT INTO table1 (date) VALUES("'today'")");
--------------------------------------------------------^

I also tried
VALUES("+'today'+") and got

Error Type:
Microsoft OLE DB Provider for Visual FoxPro (0x80004005)
Variable 'TODAY' is not found.
/counter2.asp, line 12


Any other ideas?

 
Old December 1st, 2003, 10:25 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't think you are understand the problem...

"today" is a variable in javascript. The way you are trying to use it is as a variable/field/value in the query. You can't do that, because that variable doesn't exist in the context of the query. It exists in the context of your ASP script. So you have to insert the value of the variable into the string of the query so the query actually contains a literal value.

Using this code:

today = "12/12/2003";
adoConnection.Execute("INSERT INTO table1 (date) VALUES('"+today+"')");

should result in this actual call:

adoConnection.Execute("INSERT INTO table1 (date) VALUES('12/12/2003')");

Maybe my syntax is incorrect for inserting dates into FoxPro. Maybe you need hashes (#):

today = "12/12/2003";
adoConnection.Execute("INSERT INTO table1 (date) VALUES(#"+today+"#)");

MS Access uses hashes around date values, MS-SQL can use single quotes.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old December 1st, 2003, 12:51 PM
Registered User
 
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

I assumed it was something like that but wasn't sure how to approach it.

After playing with the code I found a combination that worked.
The code:
var today;

today = "12/12/2003";
mysql = "INSERT INTO table1 (date) VALUES(";
mysql = mysql + '"'+(today) + '")';


Produced this:
INSERT INTO table1 (date) VALUES("12/12/2003")

Thanks Again!

Don






Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting variable having found it in a HashTable se tobriain C# 5 February 21st, 2008 06:50 AM
ADO UPDATE Errors rborloz Pro VB Databases 0 January 20th, 2005 04:20 AM
pls hlp!!! Microsoft ADO Data Control not found x2c4u VB Databases Basics 3 September 29th, 2004 09:42 AM
ADO Command Update hcweb Classic ASP Basics 2 January 14th, 2004 06:55 PM
Add and Update Problem with ADO bpadmana Pro VB Databases 1 August 21st, 2003 03:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.