Click to See Complete Forum and Search --> : Help with using recordset pls...


UJC
05-14-2006, 04:32 AM
Hi All.
Kinda' new... pls excuse my ignorance !-)

I have and MS Access DB, i've created a connection & Opened it, and i've created a recordset and opent it aswell - works great.

The "mdb" file has only one table, called "Pearls_Of_Wisdom", and 2 columns. one is the primary key column, also called "Key", and the second is a regular memo data-type column called "Pearl".

by writing a code like such:

Response.Write(DBRS("Key")); // DBRS is the recordset object.

It shows me only cell A0, which is the first cell in the DB.
and if i'd put in (DBRS("Pearl") it would give me A1, which is the on the first row, on the second column...
I know that i can use a loop etc... along with DBRS.MoveNext command n' stuff - but I don't want to write a full table....

Is there a way in which i could write somthing like:

Response.Write(DBRS("Key").x // whereas ".x" would indicate the row number?

So that i could indicate in one "response.write" command a specific cell to show by giving the location of it like (DBRS("column").row... or somthing like that??

Hope i explaind my self as i should have...
sorry for any ignorant mistakes i might have made..
any help would be appreciated!
thanks...

zingmatter
05-14-2006, 03:05 PM
How are you creating your recordset. (apologies if this is obvious) but did you do something like
strSQL = "SELECT * FROM Pearls_OF_Wisdom"
Set DBRS = objConn.execute(strSQL)

Then loop through the recordset items:
Do While Not DBRS.EOF

Response.write(DBRS("Key"))
DBRS.MoveNext

loop

DBRS.close
set DBRS = Nothing

Hope that helps

UJC
05-14-2006, 05:07 PM
1st of all - Thanks for replying.

2nd - i created the recordset using a jcript code(i understand VBScript, dosn't matter to me, just fond of JScript...):

DBRS = Server.CreateObject("ADODB.recordset");
DBRS.Open("Select * From Pearls_Of_Wisdom, DBConn); //where DBConn is the database connection object.

Thing is i don't want to write on line after the other, i want to write only one line (one cell from a specific row/column), and a different one evertime...

Here's what i'm trying to do basiclly:

the pearls of wisdom table (in the .mdb file) is just a table with wisdom-like sentences (stuff like "know yourself...", & "happiness comes from within" etc..). I want that every time a user gets the to the page, the server will open the .mdb file, open the pearls of wisdom table, randomly choose a sentence (by randomllay selecting a row) and then to display that sentence (from the "pearl" column on that row) to the user.

I know how to do all of that. Fact is, I allready did it once (about a year ago) but i lost the file containg my code. When i tried (3 days ago) to re-write the same code - i gues i just forgot how to do it...

any ideas?

zingmatter
05-14-2006, 05:49 PM
The SQL statement should then be something like

DBRS.Open("SELECT * FROM Pearls_Of_Wisdom WHERE Key = " + random_number. DBConn);

if not DBRS.EOF then
response.write(....etc

Sorry, I don't know JScript syntax so guessing and probably muddling in VBScript.

UJC
05-15-2006, 05:36 PM
dude - just what i needed
so simple - yet i didnt notice...
thabks very much

UJC