Solved

Parameterized Query using ASP

Posted on 1998-12-15
1
192 Views
Last Modified: 2013-12-25
I am creating a form that can be used to calculate shipping costs, depending on location, weight, and shipping method. My problem is how to create the parameterized queries to get the data I need from the SQL server database. My current formresults.asp page (listed below) display's the following error when run:

Microsoft VBScript runtime error '800a01a8'
Object required: 'DataCommand1.Fields(...).Value'
/ppad/formresults.asp, line 34

Any ideas on how to get this working ??? Thanks in advance...

Here's the formresults.asp code:

<%@ Language=VBScript%>
<%dim str_from_state, str_to_state, str_shipping_method, tmp_weight, str_weight, str_UOM
str_from_state = request.Form("select_from_state")
str_to_state = request.Form("select_to_state")
str_shipping_method = request.Form("select_shipping_method")
tmp_weight = request.Form("select_weight")
str_weight = CInt(tmp_weight)
str_UOM = Request.Form("select_UOM")
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<p>Shipment details</p>
<BR>
<p>shipping from: <%=str_from_state%><br>
shipping to: <%=str_to_state%><br>
using shipping method: <%=str_shipping_method%><br>
with shipping weight: <%=str_weight%>&nbsp<%=str_UOM%><br></p>
what type is shipping weight : <%=typename(str_weight)%>
<%
Set PPAD = Server.CreateObject("ADODB.Connection")
PPAD.ConnectionTimeout = Session("PPAD_ConnectionTimeout")
PPAD.CommandTimeout = Session("PPAD_CommandTimeout")
PPAD.Open Session("PPAD_ConnectionString"), Session("PPAD_RuntimeUserName"), Session("PPAD_RuntimePassword")
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set DataCommand1 = Server.CreateObject("ADODB.Recordset")
cmdTemp.CommandText = "SELECT MIN(minimum_weight), MAX(maximum_weight) FROM dbo.LTL_rate WHERE from_state = '" & str_from_state & "' AND to_state = '" & str_to_state & "' AND unit_of_measure = '" & str_UOM & "';"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = PPAD
DataCommand1.Open cmdTemp, , 0, 1
DataCommand1.MoveFirst
set abs_min_weight = DataCommand1.Fields(0).Value
set abs_max_weight = DataCommand1.Fields(1).value
DataCommand1.close
%>
the minimum value = <%=abs_min_weight%>
the maximum value = <%=abs_max_weight%>
<P>&nbsp;</P>

</BODY>
</HTML>
0
Comment
Question by:aguldber
1 Comment
 
LVL 1

Accepted Solution

by:
rajgn earned 100 total points
ID: 1857237
For a simple Select with Where clause Query you need not use Parameterized Query. Generally Parameterized Query is used in case of calling stored procedures with parameters. In the code you posted above replace the lines

set abs_min_weight = DataCommand1.Fields(0).Value
set abs_max_weight = DataCommand1.Fields(1).value

with

abs_min_weight = DataCommand1.Fields(0)
abs_max_weight = DataCommand1.Fields(1)

Hope this should work fine now.

all the best!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
archiving old posts 9 41
Grunt No Clean Targets 6 102
Advice on Xojo as a development tool over VB. 4 31
Best practice for a landing page 3 40
Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

914 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

12 Experts available now in Live!

Get 1:1 Help Now