|
 |
asp_databases thread: Simple db pulldown list..
Message #1 by boxenberg@l... on Mon, 19 Feb 2001 05:44:29
|
|
Hi!
I am trying to create a page that has a populated select list and then
users can make a selection from that list and then view the details of the
record. Below is the code for the page:
<% Option Explicit
Dim strConnect
%>
<!-- #INCLUDE FILE="datastore.asp" -->
<%
Dim objDC, objRS
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
objDC.Open strConnect
Set objRS = Server.CreateObject("ADODB.Recordset")
If Len(Request.QueryString("id")) <> 0 Then
objRS.Open "SELECT * FROM Employee WHERE id=" & Request.QueryString
("id"), objDC, 0, 1
If Not objRS.EOF Then
objRS.MoveFirst
%>
<TABLE BORDER=2>
<TR>
<TD><B>ID Number</B></TD>
<TD><B>First Name</B></TD>
<TD><B>Last Name</B></TD>
<TD><B>Title</B></TD>
</TR>
<TR>
<TD ALIGN="center"><%= objRS.Fields("id") %
></TD>
<TD ALIGN="left"><%= objRS.Fields
("firstname") %></TD>
<TD ALIGN="left"><%= objRS.Fields
("lastname") %></TD>
<TD ALIGN="right"><%= objRS.Fields
("title") %></TD>
</TR>
</TABLE>
<%
End If
objRS.Close
End If
objRS.Open "Northwind", objDC, 0, 1
If Not objRS.EOF Then
objRS.MoveFirst
%>
<FORM ACTION="default.asp" METHOD="get">
<SELECT NAME="id">
<OPTION></OPTION>
<%
Do While Not objRS.EOF
%>
<OPTION VALUE="<%= objRS.Fields("id") %>"><%= objRS.Fields
("firstname") & " " & objRS.Fields("lastname") %></OPTION>
<%
objRS.MoveNext
Loop
%>
</SELECT>
<INPUT type="submit" value="Submit">
</FORM>
<%
End If
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>
After my first End If statement, when I try to re-open the recordset, the
page will bomb out with a SQL Server error saying it could not find the
stored procedure "northwind" Northwind is the name of the database, and
the table I am working with is named Employee. Regardless of what value I
use after objRS.Open it will report the same error.
What am I missing here???
Thanks,
Barry
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 19 Feb 2001 18:38:04 +1100
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0375_01C09AA3.18540480
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
----- Original Message -----
From: <boxenberg@l...>
To: "ASP Databases" <asp_databases@p...>
Sent: Tuesday, February 20, 2001 1:59 AM
Subject: [asp_databases] Simple db pulldown list..
> objRS.Open "Northwind", objDC, 0, 1
<snipped>
Here are the docs for the Recordset's .Open method. You are using it
incorrectly. You can't specify the database as the first parameter...you
need to specify a table, stored procedure or SQL statement.
Open Method (ADO Recordset)
Opens a cursor.
Syntax
recordset.Open Source, ActiveConnection, CursorType, LockType, Options
Parameters
Source Optional. A Variant that evaluates to a valid Command object,
an SQL statement, a table name, a stored procedure call, a URL, or the
name of a file or Stream object containing a persistently stored
Recordset.
ActiveConnection Optional. Either a Variant that evaluates to a valid
Connection object variable name, or a String that contains
ConnectionString parameters.
CursorType Optional. A CursorTypeEnum value that determines the type
of cursor that the provider should use when opening the Recordset. The
default value is adOpenForwardOnly.
LockType Optional. A LockTypeEnum value that determines what type of
locking (concurrency) the provider should use when opening the
Recordset. The default value is adLockReadOnly.
Options Optional. A Long value that indicates how the provider should
evaluate the Source argument if it represents something other than a
Command object, or that the Recordset should be restored from a file
where it was previously saved. Can be one or more CommandTypeEnum or
ExecuteOptionEnum values.
Note If you open a Recordset from a Stream containing a persisted
Recordset, using an ExecuteOptionEnum value of adAsyncFetchNonBlocking
will not have an effect; the fetch will be synchronous and blocking.
Message #3 by "Barry Oxenberg" <boxenberg@l...> on Mon, 19 Feb 2001 00:04:04 -0800
|
|
Hi Ken!
Thank you for the reply, and the reference material!
:-)
I got the asp page working and it is not so much that I was using the
Open method incorrectly, but I had a few other things wrong as well.
First off, I apologize if I neglected to include in my original post
that even when I specified "Employee" as the parameter for objRs I was
getting a SQL error about not finding a stored procedure.
After reading the documentation you sent it got me wondering and then I
went in and actually looked at the table. Imagine my surprise when I
discovered that the name of the table I was looking for is actually
called " Employees". Additionally, what I thought was the "id" field in
the database was actually called "EmployeeId."
So, after correcting the code on my page to properly match the table and
field names, the "application" works now!
:-)
Thank you for your help.
Regards,
Barry
|
|
 |