473,388 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

how many items SQL

59
hello everybody!

I have an sql statment, and I want to add all the data into an array.

when I declare the array I need to write the amount of items.

how can I know before I do the loop rs.EOF = false
how many items the sql statment has ?

thanks in advance,
Idan
Mar 3 '08 #1
3 1161
shweta123
692 Expert 512MB
Hi,

To change upper bound for the array at run time , Redim statement is used.
Syntax:
Redim arrayname(arraylimit)

Example:
<%
Dim myArray(0)
Redim PRESERVE myArray(uBound(myArray)+1)
%>

Explanation :
In the above example Array called as myArray is defined with zero dimensions. Afterwords array size is incremented by one.

hello everybody!

I have an sql statment, and I want to add all the data into an array.

when I declare the array I need to write the amount of items.

how can I know before I do the loop rs.EOF = false
how many items the sql statment has ?

thanks in advance,
Idan
Mar 3 '08 #2
DrBunchman
979 Expert 512MB
Hi Zivon,

You can use the rs.RecordCount property to get the number of records returned by your query. To get this to work you'll need to do the following:
  1. In order to to use a variable as your array size you'll need to dimension the array without a size then redim it with the record count.
  2. You need to specify the correct cursor type when you open the recordset. The default cursor type is adOpenForwardOnly which doesn't allow the RecordCount property.
Example code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. Dim oConn, rs, sSQL
  4. Dim sArray()
  5. Dim x
  6.  
  7. Set oConn = server.createobject("ADODB.connection")
  8. oConn.Open Session("sConStr")
  9.  
  10. Set rs= server.createobject("ADODB.Recordset")
  11. sSQL=" SELECT * FROM Table1 "
  12.  
  13. 'The 3 in the rs.Open statement specifies the cursor type as adOpenStatic which allows the RecordCount property
  14. rs.Open sSQL, oConn, 3
  15.  
  16. ReDim sArray(rs.RecordCount)
  17. x = 0
  18. Do until rs.eof
  19. sArray(x) = rs("Column1")
  20. x = x + 1
  21. rs.MoveNext
  22. Loop
  23. %>
  24.  
Let me know if you have any problems.

Hope this helps,

Dr B
Mar 3 '08 #3
zivon
59
Thanks for you both :)

Have a nice week !
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Donnal Walter | last post by:
The following method is defined in one of my classes: def setup(self, items={}): """perform setup based on a dictionary of items""" if 'something' in items: value = items # now do something...
4
by: mb | last post by:
what is the best way to do this: In a game I want to a class called "Items". This class will have the game items public class Items { public int Chair public int Table . . .and so on . . .
9
by: Alpha | last post by:
Hi, How can I set all the items in a listbox to be selected? I can't find a property or mehtod to do it so I thought I'll try using setselected method but I need to find out how many items are in...
2
by: dave | last post by:
This little problem is driving me nuts!! On my webform page I create 2 variables.. Protected p_dml As String = "I" Public Const mwv_id As Integer = 0 ' originally had mwv_id as Protected
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
2
by: hsuntn | last post by:
I am grabbing Outlook MailItems using the Items property on my Outlook inbox. When I iterate through them, I notice that they are not ordered in ReceivedTime or CreationTime order. For example, ...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
13
by: Joel Koltner | last post by:
Is there an easy way to get a list comprehension to produce a flat list of, say, for each input argument? E.g., I'd like to do something like: for x in range(4) ] ....and receive
13
by: PetterL | last post by:
I writing a program where I read menu items from a file. But I have problem when I click an menu item i want it to mark that one as checked but I cant access the menu object of that item to see...
2
by: mygirl22 | last post by:
Hi, I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen..... What i need now is to know how to assign specific values to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.