Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Recordsets - how to get just one row?

Status
Not open for further replies.

StevenB

IS-IT--Management
Sep 25, 2000
247
US
Howdy all, very much a novice ASP programmer. I'm working with an Access 2000 database, and I somehow managed to create one page that uses ASP to loop through all of the records in one table and displays a schedule - success!

Next, I need to understand how to select only one row from a table and draw an entire page based on fields related to that one row. Ultimately, I anticipate feeding that value (ie which row to use) from a separate page. So, for example, I would tell the page the "primary key" for the row I want to display, and it would give me a bunch of data back related to that row.

But, despite doing some heavy reading, I can't seem to figure out how to select just one row from the table.

I know this is a newbie question, I would be most appreciative if someone could even point me in the direction of a tutorial or something that covers this topic.

This is the code I'm using in the page that works:

---
<%
Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2

Dim objConn, objRS
Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Set objRS = Server.CreateObject(&quot;ADODB.Recordset&quot;)

Dim strDatabaseType
strDatabaseType = &quot;Access&quot;

objConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _
&quot;Data Source=C:\db.mdb;&quot; & _
&quot;Persist Security Info = False&quot;

objRS.Open &quot;qrySelectAllGameInfo&quot;, objConn, adOpenForwardOnly, adLockReadOnly, adCmdTable

Followed by your typical:
While Not objRS.EOF
~lots of stuff~
Wend

---------

Any help would be greatly appreciated!

Steve
 
In order to select a row of records you can do a short SELECT to extract that row by some criteria in one of the fields or columns using the WHERE clause.

so say I want to get one person out of a hunred rows or records of a table named users. the name is of course onpnt [wink]
what you want to do is create a short SQL statement to SELECT on that criteria &quot;onpnt&quot;
so declare the var
dim sqltxt
then write the select statement
sqltxt = &quot;SELECT * FROM users WHERE name = 'onpnt'&quot;
what this did was selected all the records in the row for the field name holding onpnt.

of course you need to execute that statement seeing as all it is doing is sitting in the variable.
this one should look familiar already
RS.Open sqltxt, connection varaible

now you have a row of records only pertaining to onpnt.

hope that helps out ---------------------------------------
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top