Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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
  #1 (permalink)  
Old February 25th, 2005, 08:28 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to howbadboy
Default Parameterised Access Query in javascript

HI,

I'm new to asp/javascript and am strugglling to get to grips with using a form input as an input to a stored procedure in Access.

I've seen a lot of code for VbScript and Ole Db (i'm using odbc) and am still confused!!

Basically I have the following code:

<%@LANGUAGE="JAVASCRIPT"%>
</head>
<body>
<%

    var dbConn = Server.CreateObject("ADODB.Connection");
    dbConn.Open("custconn");

    var dbComm = Server.CreateObject("ADODB.Command");

    dbComm.commandtext = "cityQuery";
    dbComm.commandtype = adCmdStoredProc;

    var objParam = dbComm.CreateParameter("City", adVarChar, adParamInput);
    dbComm.Parameters.Append(dbComm);
    objCommand.Parameters("City") = "London";

    dbComm.activeconnection = dbConn;
    var rSet = Server.CreateObject("ADODB.Recordset");
    dbComm.execute();
%>
</body>
</html>

I'm looking to return all records whose city value is 'London'
I'm trying to kinda copy VBScript examples but really am coming up against the wall...as i said...this is all pretty new territory to me.

Does anyone have some url's that will go through this on a pretty basic or simple level..

thanks

alan

  #2 (permalink)  
Old February 26th, 2005, 07:49 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Please don't post the same question in two forums.

Assuming your connection succeeds and you have defined the adVarChar etc, normally via an include file, then the only thing that jumps out at me is:
Code:
objCommand.Parameters("City") = "London";
JavaScript doesn't understand default object properties so you need:
Code:
objCommand.Parameters("City").value = "London";
Remember this when you try to output using the recordset:
Code:
//var rSet = Server.CreateObject("ADODB.Recordset"); NOT NEEDED
var rSet =  dbComm.execute();
if (rSet.EOF && rSet.BOF)
{
  //No records
}
else
{
  while (!rSet.EOF)
  {
    Response.Write(rSet.fields(0).value + "<br>");
    rSet.moveNext();
  }
}
rSet.close();
--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old February 26th, 2005, 12:39 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to howbadboy
Default

cheers for the quick reply...and apologies for the double post...
hopefully this will do the trick
thanks again



Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Access Database Query panuvin Javascript How-To 28 May 9th, 2008 01:53 PM
Parameterised Input stored procedure fdtoo SQL Server 2000 0 November 7th, 2007 07:11 AM
Query string to a external javascript file anujrathi ASP.NET 1.0 and 1.1 Professional 1 November 4th, 2006 01:26 AM
Open a Parameterised Query to screen using code vbark Access VBA 2 June 5th, 2006 05:46 PM
how to call xml using javascript then query Apocolypse2005 Javascript 0 January 11th, 2006 10:53 AM





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