Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Randomly Generated Recordset - Same Recordset with different sequence every time


Message #1 by "ARTI MAHOBE" <arti_mahobe@h...> on Mon, 23 Apr 2001 17:38:52 +0530
Hi there,

I am working with a firm as a Conbsultant (Software). I am developing a

component in ASP . This should return a Random Recordset (i.e.

Recordset wih different sequence every time the Page is executed. It is

not so that I have to return a No. of Records randomly selected from a

Table. But I have to return same no. of records (Reordset) every time

but with a different sequence.



How can I do this, How do I Add a field to Recordset at Run time and

Edit that Field. This is having a high priority, so please reply for

this as soon as possible. I would really be thankful to you.



Arti

Message #2 by Hal Levy <hal.levy@s...> on Mon, 23 Apr 2001 09:55:56 -0400
This message is in MIME format. Since your mail reader does not understand

this format, some or all of this message may not be legible.



------_=_NextPart_001_01C0CBFD.1E3BE4E0

Content-Type: text/plain;

	charset="iso-8859-1"



Assuming you have an identity field- and it uses numbers only:





1. Get the recordset

2. getrows into an array

3. Get the number of array elements

4. Loop 

5.  random number generated (in array range)

6.  make sure that item wasn't out put before. (compare to a variable that

tracks this)

7.  if new then output and add to tracking variable

8. end loop until all rows are output (can't use EOF here- you need to

actually count each time something is written out)



This will be an intense process.



You might find it easier to keep the order the same- but pick a random point

to start outputting on and loop around to the beginning. If that meets  your

needs, you will get better performance.





Hal Levy

StarMedia Network, Inc.

Intranet Development Manager



-----Original Message-----

From: ARTI MAHOBE [mailto:arti_mahobe@h...]

Sent: Monday, April 23, 2001 8:09 AM

To: ASP Databases

Subject: [asp_databases] Randomly Generated Recordset - Same Recordset

with different sequence every time





Hi there,

I am working with a firm as a Conbsultant (Software). I am developing a

component in ASP . This should return a Random Recordset (i.e.

Recordset wih different sequence every time the Page is executed. It is

not so that I have to return a No. of Records randomly selected from a

Table. But I have to return same no. of records (Reordset) every time

but with a different sequence.



How can I do this, How do I Add a field to Recordset at Run time and

Edit that Field. This is having a high priority, so please reply for

this as soon as possible. I would really be thankful to you.



Arti



---

SoftArtisans helps developers build robust, scalable Web applications!

Excel Web reports, charts: http://www.softartisans.com/excelwriter.html

File uploads: http://www.softartisans.com/saf.html

Transactional file management: http://www.softartisans.com/saf1.html

Scalability: http://www.softartisans.com/saxsession.html

ASPstudio value pack: http://www.softartisans.com/aspstudiosuite.html




$subst('Email.Unsub')




Message #3 by "Charles Feduke" <webmaster@r...> on Mon, 23 Apr 2001 20:43:03 -0400
    Oh man.



' cursor location

Private Const adUseClient = 3

' cursor types

Private Const adOpenStatic = 3

' lock types

Private Const adLockBatchOptimistic = 4

' data types

Private Const adInteger = 3

Private Const adVarChar = &HC8

' field attributes

Private Const adFldIsNullable = &H20



' you can find all the constants if you look around at msdn.microsoft.com; or

'    check www.adopenstatic.com for a good example on including the ADODB

'    (and all its constants) in the global.asa.



Dim rsRec

Set rsRec = Server.CreateObject("ADODB.Recordset")

rsRec.CursorLocation = adUseClient

rsRec.Fields.Append "ID", adInteger

rsRec.Fields.Append "Name", adVarChar, 40, adFldIsNullable

' open with no datasource

rsRec.Open , , adOpenStatic, adLockBatchOptimistic



rsRec.AddNew

rsRec("ID") = 12

rsRec("Name") = "Chuck"

rsRec.AddNew

rsRec("ID") = 13

rsRec("Name") = "Cathy"



rsRec.UpdateBatch



' eliminate

rsRec.Close



    Whee!



- Chuck





----- Original Message -----

From: "ARTI MAHOBE" <arti_mahobe@h...>

To: "ASP Databases" <asp_databases@p...>

Sent: Monday, April 23, 2001 8:08 AM

Subject: [asp_databases] Randomly Generated Recordset - Same Recordset with

different sequence every time





> Hi there,

> I am working with a firm as a Conbsultant (Software). I am developing a

> component in ASP . This should return a Random Recordset (i.e.

> Recordset wih different sequence every time the Page is executed. It is

> not so that I have to return a No. of Records randomly selected from a

> Table. But I have to return same no. of records (Reordset) every time

> but with a different sequence.

>

> How can I do this, How do I Add a field to Recordset at Run time and

> Edit that Field. This is having a high priority, so please reply for

> this as soon as possible. I would really be thankful to you.

>

> Arti



Message #4 by "Darin Strait" <dstrait@e...> on Mon, 23 Apr 2001 22:17:20 -0400
On SQL Server 7 and up, try ordering resultsets by NewID() for random

orders:



SELECT * FROM pubs..authors ORDER BY NEWID()





Darin Strait, MS SQL Server Development and Administration

http://home.earthlink.net/~dstrait/professional/resume.htm





----- Original Message -----

From: "Charles Feduke" <webmaster@r...>

To: "ASP Databases" <asp_databases@p...>

Sent: Monday, April 23, 2001 8:43 PM

Subject: [asp_databases] Re: Randomly Generated Recordset - Same Recordset

with different sequence every time





>     Oh man.

>

> ' cursor location

> Private Const adUseClient = 3

> ' cursor types

> Private Const adOpenStatic = 3

> ' lock types

> Private Const adLockBatchOptimistic = 4

> ' data types

> Private Const adInteger = 3

> Private Const adVarChar = &HC8

> ' field attributes

> Private Const adFldIsNullable = &H20

>

> ' you can find all the constants if you look around at msdn.microsoft.com;

or

> '    check www.adopenstatic.com for a good example on including the ADODB

> '    (and all its constants) in the global.asa.

>

> Dim rsRec

> Set rsRec = Server.CreateObject("ADODB.Recordset")

> rsRec.CursorLocation = adUseClient

> rsRec.Fields.Append "ID", adInteger

> rsRec.Fields.Append "Name", adVarChar, 40, adFldIsNullable

> ' open with no datasource

> rsRec.Open , , adOpenStatic, adLockBatchOptimistic

>

> rsRec.AddNew

> rsRec("ID") = 12

> rsRec("Name") = "Chuck"

> rsRec.AddNew

> rsRec("ID") = 13

> rsRec("Name") = "Cathy"

>

> rsRec.UpdateBatch

>

> ' eliminate

> rsRec.Close

>

>     Whee!

>

> - Chuck

>

>

> ----- Original Message -----

> From: "ARTI MAHOBE" <arti_mahobe@h...>

> To: "ASP Databases" <asp_databases@p...>

> Sent: Monday, April 23, 2001 8:08 AM

> Subject: [asp_databases] Randomly Generated Recordset - Same Recordset

with

> different sequence every time

>

>

> > Hi there,

> > I am working with a firm as a Conbsultant (Software). I am developing a

> > component in ASP . This should return a Random Recordset (i.e.

> > Recordset wih different sequence every time the Page is executed. It is

> > not so that I have to return a No. of Records randomly selected from a

> > Table. But I have to return same no. of records (Reordset) every time

> > but with a different sequence.

> >

> > How can I do this, How do I Add a field to Recordset at Run time and

> > Edit that Field. This is having a high priority, so please reply for

> > this as soon as possible. I would really be thankful to you.

> >

> > Arti

>

>

  Return to Index