Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Error Message in ASP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-03, 00:58
Dooogie352 Dooogie352 is offline
Registered User
 
Join Date: Apr 2003
Posts: 2
Error Message in ASP

I'm new to this forum and to ASP, so please be patient. I am attempting to complete an ASP project and all is well except for an error message I receive when I submit one page. I figure I am missing something obvious, but I have spent a few hours playing with this code with no luck. I am hoping for some assistance from the experts so I can finish this before I go nuts. Feel free to reply to me directly at doogie352@aol.com. Any assistance would be greatly appreciated.

The error message is:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/schedule/vehicle_select.asp, line 41

The code is:

<%
' # Open the database to get Column names for the drop down list #####
'################################################# #####################
set Rsemaa = Server.CreateObject("ADODB.Recordset")
Rsemaa.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& server.MapPath("/databases/schedule.mdb")
Rsemaa.Source = "SELECT * FROM tbl_vehicles"
Rsemaa.CursorType = 0
Rsemaa.CursorLocation = 2
Rsemaa.LockType = 3
Rsemaa.Open()

'### If the search has been submitted create the SQL string and open another DB connection for the search
'################################################# ################################################## #####

If request.querystring() <> "" then

Dim SQLstring

If request.form("field") = "" then
Response.Write("No records returned. Please select status from drop down.")
Else
SQLstring = "SELECT * FROM tbl_vehicles WHERE vehicle_number=" & request.form("field") & " "
End if


set RsSearch = Server.CreateObject("ADODB.Recordset")
RsSearch.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& server.MapPath("/databases/schedule.mdb")
RsSearch.Source = SQLstring
RsSearch.CursorType = 0
RsSearch.CursorLocation = 2
RsSearch.LockType = 3
RsSearch.Open()
End if
%>



<form name="form1" method="post" action="vehicle_select.asp?search">
<br>
Vehicle Name&nbsp;
<select name="field">
<% do while not rsemaa.eof %>

<option value="<%= rsemaa("vehicle_number")%>"><%= rsemaa("vehicle_number")%></option>

<%
rsemaa.movenext
Loop
%>
</select>

<input type="submit" name="Submit" value="Submit">

<hr>
<br>

<font face="Arial, Helvetica, sans-serif" size="2">

<%
'#### Print the search results to the a table on the page
If request.querystring() <> "" then %>

<table border=0 align=center cellpadding=3 cellspacing=0 width=764><thead><tr>
<td><b>Vehicle</td>
</tr></thead><tbody>
<tr>
<td><hr></td>
</tr>

<% do while not RsSearch.EOF %>
<tr>
<td><a href="vehicle_select2.asp?ID=<%= RsSearch("vehiclenumber") %>"><%= RsSearch("vehiclenumber") %></A></td>
</tr>
<tr>
<td><hr></td>
</tr>
<%
RsSearch.MoveNext
Loop
%>
</tbody></table><p>
<%
'#### Close it off ######
RsSearch.Close()
Set RsSearch = nothing
End if %>
Reply With Quote
  #2 (permalink)  
Old 04-04-03, 02:02
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
???

I'm not yet a 'guru' but I've seen this error plenty of times.

My experience with this error message says that you're somehow defining your SQL query using a field that doesn't exist in the database.

I don't know how your data is set up, so you might want to check that your SQL statement against your table definition...

SQLstring = "SELECT * FROM tbl_vehicles WHERE vehicle_number=" & request.form("field") & " "

Is there a tbl_vehicles with a field named vehicle_number? And I'm just a little suspicious about how this will act if you pass a blank value in your "field" variable.

Tim
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 04-04-03, 09:06
Dooogie352 Dooogie352 is offline
Registered User
 
Join Date: Apr 2003
Posts: 2
Follow-up

I appreciate the reply....unfortunately there is a table and field as described. I double checked and it's there. But thans for the idea. Any other suggestions?
Reply With Quote
  #4 (permalink)  
Old 04-04-03, 11:45
bciarcia bciarcia is offline
Registered User
 
Join Date: Apr 2003
Location: Connecticut
Posts: 17
Re: ???

try putting single quotes around the value like this;

SQLstring = "SELECT * FROM tbl_vehicles WHERE vehicle_number= '" & request.form("field") & "'"

because you are looking for an integer SQL likes to have " ' " around the variables.

Let me know if it works.






Quote:
Originally posted by MrWizard
I'm not yet a 'guru' but I've seen this error plenty of times.

My experience with this error message says that you're somehow defining your SQL query using a field that doesn't exist in the database.

I don't know how your data is set up, so you might want to check that your SQL statement against your table definition...

SQLstring = "SELECT * FROM tbl_vehicles WHERE vehicle_number=" & request.form("field") & " "

Is there a tbl_vehicles with a field named vehicle_number? And I'm just a little suspicious about how this will act if you pass a blank value in your "field" variable.

Tim
Reply With Quote
  #5 (permalink)  
Old 04-04-03, 15:35
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Re: Error Message in ASP

Just another thought....

Since I don't know what your data looks like, I thought it was at least worth mentioning that one common source of SQL errors of this type is having apostrophes or pipe characters in your data.

If by chance your data contains either a " ' " or a " | " character, then this could definitely cause the error you got, in which case you would just have to clean up the data before putting it in the SQL string.

Tim
__________________
Tim
Reply With Quote
  #6 (permalink)  
Old 04-05-03, 20:18
rhs98 rhs98 is offline
Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 440
if the request.form("field") is not a number this error may be caused by the sql parser beliving that the data inserted is a field your requesting;

i.e.
Code:
SQLstring = "SELECT * FROM tbl_vehicles WHERE vehicle_number= " & request.form("field") & " " response.write sqlstring
would output this if the form field called field = "x"
Code:
SELECT * FROM tbl_vehicles WHERE vehicle_number=x

the sql parser will assume this to be a column. Strings must be delimited using the ' symbol usually
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On