|
 |
asp_databases thread: How to Pass RecordSource Values to Array?
Message #1 by MinhCDao@a... on Sat, 25 Nov 2000 03:15:28 EST
|
|
--part1_e.5605856.2750cf20_boundary
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
Hi Pro
Please find what wrong in my codes
strSQL = "select id from Students where major = 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i = 1 to objRS.EOF
idArray(i) = objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao
Message #2 by "Pat Waddington" <paw@s...> on Sat, 25 Nov 2000 14:53:22 -0000
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_002C_01C056EF.7501D240
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I don't think you can use objRS.EOF to signal the end of a loop and you
need to make sure the cursor moves on. I assume you are trying to build
an array containing Student IDs.
Try this:
strSQL =3D "select id from Students where major =3D 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
i =3D 1
objRS.MoveFirst
Do Until objRS.EOF
idArray(i) =3D objRS("id")
i =3D i+1
objRS.MoveNext
Loop
Unless you are absolutely certain that i will not exceed 20, make the
array dynamic by using
Dim idArray() instead of Dim idArray(20)
then Redim the array when the loop has finished (the last valid index
will be (i - 1))
The first index in an array is actually zero, but a lot of people like
to start from 1 as they find it less confusing.
HTH
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 8:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL =3D "select id from Students where major =3D 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i =3D 1 to objRS.EOF
idArray(i) =3D objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao ---
FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND
INSIGHTS IN YOUR INBOX!
Get the latest and best C++, Visual C++, Java, Visual Basic, and XML
tips, tools, and
developments from the experts. Sign up for one or more of EarthWeb?s
FREE IT newsletters at http://www.earthweb.com today!
paw@s...
$subst('Email.Unsub')
Message #3 by "Dallas Martin" <dmartin@z...> on Sun, 26 Nov 2000 16:56:30 -0500
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_001D_01C057C9.D324C820
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
VBScript arrays are usually zero-based.
Your for next loop should set the loop counter to 0
ie. for x =3D 0 to somei nteger value (NOT EOF,which is a boolean test)
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 3:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL =3D "select id from Students where major =3D 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i =3D 1 to objRS.EOF
idArray(i) =3D objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao ---
FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND
INSIGHTS IN YOUR INBOX!
Get the latest and best C++, Visual C++, Java, Visual Basic, and XML
tips, tools, and
developments from the experts. Sign up for one or more of EarthWeb?s
FREE IT newsletters at http://www.earthweb.com today!
$subst('Email.Unsub')
Message #4 by "Kevin" <webmaster@m...> on Sun, 26 Nov 2000 20:29:03 -0500
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0013_01C057E7.84243080
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Right, instead try using the RecordCount property for the RecordSet
object in the For statement.
For i =3D 0 To (objRS.RecordCount - 1)
Regards,
Kevin Fields
----- Original Message -----
From: Dallas Martin
To: ASP Databases
Sent: Sunday, November 26, 2000 4:56 PM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
VBScript arrays are usually zero-based.
Your for next loop should set the loop counter to 0
ie. for x =3D 0 to somei nteger value (NOT EOF,which is a boolean
test)
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 3:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL =3D "select id from Students where major =3D 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i =3D 1 to objRS.EOF
idArray(i) =3D objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao ---
FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND
INSIGHTS IN YOUR INBOX!
Get the latest and best C++, Visual C++, Java, Visual Basic, and XML
tips, tools, and
developments from the experts. Sign up for one or more of EarthWeb?s
FREE IT newsletters at http://www.earthweb.com today!
$subst('Email.Unsub')
---
NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS? Is FREE okay?
Visit EarthWeb for the latest in IT Management, Software Development,
Web Development, Networking & Communications, and Hardware & Systems.
Click on http://www.earthweb.com for FREE articles, tutorials,
and discussions from the experts.
drunkendruid@h...
$subst('Email.Unsub')
Message #5 by Rollinger Marcel <romatet@v...> on Mon, 27 Nov 2000 01:52:12 +0000
|
|
--------------C36574B1D345BA1A3FE54DF5
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
that's my solution,
dim sql
dim lngMaxRecord
dim i
dim arrRecords()
sql = "select id from Students where major = 'COSC'"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, objConn
rs.movelast
lngMaxRecord = rs.recordcount
redim arrRecords(lngMaxRecord)
for i = 0 to ubound(arrRecords)-1
do action......
next
by romatet@v...
www.romatet.com
Dallas Martin schrieb:
> VBScript arrays are usually zero-based. Your for next loop should set
> the loop counter to 0 ie. for x = 0 to somei nteger value (NOT
> EOF,which is a boolean test) ----- Original Message -----
>
> From: MinhCDao@a...
> To: ASP Databases
> Sent: Saturday, November 25, 2000 3:15 AM
> Subject: [asp_databases] How to Pass RecordSource Values to
> Array?
>
>
>
> Hi Pro
>
> Please find what wrong in my codes
>
> strSQL = "select id from Students where major = 'COSC'"
> objRS.open strSQL, objConn
> Dim i
> Dim idArray(20)
> objRS.MoveFirst
> For i = 1 to objRS.EOF
> idArray(i) = objRS("id").value(i) ' get sid from the cursor
> Next
>
> Can I do that?
>
> Thanks for your help.
>
> Minh C. Dao ---
> FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND
> INSIGHTS IN YOUR INBOX!
> Get the latest and best C++, Visual C++, Java, Visual Basic,
> and XML tips, tools, and
> developments from the experts. Sign up for one or more of
> EarthWeb?s
> FREE IT newsletters at http://www.earthweb.com today!
> dmartin@z...
> $subst('Email.Unsub')
>
> ---
> NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS? Is FREE okay?
> Visit EarthWeb for the latest in IT Management, Software Development,
> Web Development, Networking & Communications, and Hardware & Systems.
> Click on http://www.earthweb.com for FREE articles, tutorials,
> and discussions from the experts.
> $subst('Email.Unsub')
Message #6 by "jigs gandhi" <newsgroup@h...> on Mon, 27 Nov 2000 10:46:16 +0530
|
|
This is a multi-part message in MIME format.
------=_NextPart_000_0088_01C0585F.44F4B880
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
hi,
try
myArray =3D recordset.getRows()
this will create a 2 dimensional array and put all the data from the
recordset into the array
jigs
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 1:45 PM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL =3D "select id from Students where major =3D 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i =3D 1 to objRS.EOF
idArray(i) =3D objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao ---
FREE SOFTWARE DEVELOPMENT CODE, CONTENT, AND
INSIGHTS IN YOUR INBOX!
Get the latest and best C++, Visual C++, Java, Visual Basic, and XML
tips, tools, and
developments from the experts. Sign up for one or more of EarthWeb?s
FREE IT newsletters at http://www.earthweb.com today!
$subst('Email.Unsub')
Message #7 by Navani <navanid@y...> on Sun, 26 Nov 2000 20:48:59 -0800 (PST)
|
|
Hello,
I have found that you are trying to move a
recordset value into an array by using loop. I think
it's not a proper way.
You can use like this
ArrObj= objRs.GetRows()
so that all the records in the objRs recordset would
be moved into ArrObj Array.
No need to use loops and all
with luv,
Navani
--- Pat Waddington <paw@s...> wrote:
> I don't think you can use objRS.EOF to signal the
> end of a loop and you need to make sure the cursor
> moves on. I assume you are trying to build an array
> containing Student IDs.
>
> Try this:
> strSQL = "select id from Students where major
> 'COSC'"
> objRS.open strSQL, objConn
> Dim i
> Dim idArray(20)
> i = 1
> objRS.MoveFirst
> Do Until objRS.EOF
> idArray(i) = objRS("id")
> i = i+1
> objRS.MoveNext
> Loop
>
> Unless you are absolutely certain that i will not
> exceed 20, make the array dynamic by using
> Dim idArray() instead of Dim idArray(20)
> then Redim the array when the loop has finished (the
> last valid index will be (i - 1))
>
> The first index in an array is actually zero, but a
> lot of people like to start from 1 as they find it
> less confusing.
>
> HTH
>
> ----- Original Message -----
> From: MinhCDao@a...
> To: ASP Databases
> Sent: Saturday, November 25, 2000 8:15 AM
> Subject: [asp_databases] How to Pass RecordSource
> Values to Array?
>
>
>
> Hi Pro
>
> Please find what wrong in my codes
>
> strSQL = "select id from Students where major
> 'COSC'"
> objRS.open strSQL, objConn
> Dim i
> Dim idArray(20)
> objRS.MoveFirst
> For i = 1 to objRS.EOF
> idArray(i) = objRS("id").value(i) ' get sid from
> the cursor
> Next
>
> Can I do that?
>
> Thanks for your help.
>
> Minh C. Dao =====
With luv,
Navani
Message #8 by "Ken Schaefer" <ken@a...> on Mon, 27 Nov 2000 17:41:49 +1100
|
|
This is an extremely *expensive* operation - has no one heard of .getRows()?
objRS.Open
If not objRS.EOF then
arrResults = objRS.getRows
End if
objRS.close
Set objRS = nothing
...
If isArray(objRS) then
For i = 1 to UBound(arrResults, 2)
Else
' No results
End if
http://www.adopenstatic.com/faq/recordcountalternatives.asp
Cheers
Ken
----- Original Message -----
From: "Rollinger Marcel" <romatet@v...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, November 27, 2000 12:52 PM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
> Hi,
>
> that's my solution,
>
> dim sql
> dim lngMaxRecord
> dim i
> dim arrRecords()
> sql = "select id from Students where major = 'COSC'"
> set rs = Server.CreateObject("ADODB.Recordset")
> rs.open sql, objConn
> rs.movelast
> lngMaxRecord = rs.recordcount
> redim arrRecords(lngMaxRecord)
> for i = 0 to ubound(arrRecords)-1
> do action......
> next
>
> by romatet@v...
> www.romatet.com
Message #9 by "Ken Schaefer" <ken@a...> on Mon, 27 Nov 2000 17:44:09 +1100
|
|
aargh - Use .getRows() instead:
objRS.Open
If not objRS.EOF then
arrResults = objRS.getRows()
End if
objRS.close
Set objRS = nothing
...
If isArray(arrResults) then
' There are results
Else
' There are no results
End if
.getRows creates a two-dimensional VBScript array containing the records in
your recordset. The first dimension is the fields and the second dimension
your records...
Cheers
Ken
----- Original Message -----
From: "Pat Waddington" <paw@s...>
To: "ASP Databases" <asp_databases@p...>
Sent: Sunday, November 26, 2000 1:53 AM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
I don't think you can use objRS.EOF to signal the end of a loop and you need
to make sure the cursor moves on. I assume you are trying to build an array
containing Student IDs.
Try this:
strSQL = "select id from Students where major = 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
i = 1
objRS.MoveFirst
Do Until objRS.EOF
idArray(i) = objRS("id")
i = i+1
objRS.MoveNext
Loop
Unless you are absolutely certain that i will not exceed 20, make the array
dynamic by using
Dim idArray() instead of Dim idArray(20)
then Redim the array when the loop has finished (the last valid index will
be (i - 1))
The first index in an array is actually zero, but a lot of people like to
start from 1 as they find it less confusing.
HTH
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 8:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL = "select id from Students where major = 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i = 1 to objRS.EOF
idArray(i) = objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao
Message #10 by "Ken Schaefer" <ken@a...> on Mon, 27 Nov 2000 17:45:02 +1100
|
|
No, no, no:
http://www.adopenstatic.com/faq/recordcountalternatives.asp
Use .getRows() instead - moves the records in your Recordset to a 0-based
VBScript array.
Cheers
Ken
----- Original Message -----
From: "Kevin" <webmaster@m...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, November 27, 2000 12:29 PM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
Right, instead try using the RecordCount property for the RecordSet object
in the For statement.
For i = 0 To (objRS.RecordCount - 1)
Regards,
Kevin Fields
----- Original Message -----
From: Dallas Martin
To: ASP Databases
Sent: Sunday, November 26, 2000 4:56 PM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
VBScript arrays are usually zero-based.
Your for next loop should set the loop counter to 0
ie. for x = 0 to somei nteger value (NOT EOF,which is a boolean test)
----- Original Message -----
From: MinhCDao@a...
To: ASP Databases
Sent: Saturday, November 25, 2000 3:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL = "select id from Students where major = 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i = 1 to objRS.EOF
idArray(i) = objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Message #11 by "Ken Schaefer" <ken@a...> on Mon, 27 Nov 2000 17:51:22 +1100
|
|
Just as a followup, since there seems to be some ignorance on .getRows, the
PlatformSDK docs on .getRows are here:
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/dasdk/mdam9r
g3.htm
Some other links:
http://www.learnasp.com/advice/whygetrows.asp
and
http://www.learnasp.com/learn/dbtablegetrows.asp
If you need help on arrays:
http://www.learnasp.com/learn/arrays.asp
http://www.learnasp.com/learn/arrays2.asp
http://www.learnasp.com/learn/arrays3.asp
Cheers
Ken
Message #12 by Van Tolhuyzen Koen <Koen.VanTolhuyzen@c...> on Mon, 27 Nov 2000 11:16:33 +0100
|
|
how about :
sql = "select id from Students where major = 'COSC'"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, objConn
arrResult = rs.GetRows
This is much fasters and allows adForwardOnly too !
Koen
-----Original Message-----
From: Rollinger Marcel
To: ASP Databases
Sent: 27/11/00 2:52
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
Hi,
that's my solution,
dim sql
dim lngMaxRecord
dim i
dim arrRecords()
sql = "select id from Students where major = 'COSC'"
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql, objConn
rs.movelast
lngMaxRecord = rs.recordcount
redim arrRecords(lngMaxRecord)
for i = 0 to ubound(arrRecords)-1
do action......
next
by romatet@v...
www.romatet.com
Dallas Martin schrieb:
VBScript arrays are usually zero-based. Your for next loop should set
the loop counter to 0 ie. for x = 0 to somei nteger value (NOT EOF,which
is a boolean test) ----- Original Message -----
From: MinhCDao@a... <mailto:MinhCDao@a...>
To: ASP <mailto:asp_databases@p...> Databases
Sent: Saturday, November 25, 2000 3:15 AM
Subject: [asp_databases] How to Pass RecordSource Values to Array?
Hi Pro
Please find what wrong in my codes
strSQL = "select id from Students where major = 'COSC'"
objRS.open strSQL, objConn
Dim i
Dim idArray(20)
objRS.MoveFirst
For i = 1 to objRS.EOF
idArray(i) = objRS("id").value(i) ' get sid from the cursor
Next
Can I do that?
Thanks for your help.
Minh C. Dao
Message #13 by "Dallas Martin" <dmartin@z...> on Mon, 27 Nov 2000 16:15:53 -0500
|
|
Ken,
There is no ignorance of "getrow()". I use it
all the time.
It seemed to me that the original question contained
several errors:
1) Improperly constructed "for..next" loop
2) Use of a one-based array without explicit declaration
of such. VB Arrays default to zero-based.
My response sought to address the user's low knowledge
level about VB programming in general.
Thanks,
Dallas Martin
----- Original Message -----
From: "Ken Schaefer" <ken@a...>
To: "ASP Databases" <asp_databases@p...>
Sent: Monday, November 27, 2000 1:51 AM
Subject: [asp_databases] Re: How to Pass RecordSource Values to Array?
> Just as a followup, since there seems to be some ignorance on .getRows,
the
> PlatformSDK docs on .getRows are here:
>
>
http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/dasdk/mdam9r
> g3.htm
>
> Some other links:
> http://www.learnasp.com/advice/whygetrows.asp
> and
> http://www.learnasp.com/learn/dbtablegetrows.asp
>
> If you need help on arrays:
> http://www.learnasp.com/learn/arrays.asp
> http://www.learnasp.com/learn/arrays2.asp
> http://www.learnasp.com/learn/arrays3.asp
>
> Cheers
> Ken
>
>
|
|
 |