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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through databases with VBScript

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have some simple code that I am trying to get to work. Half the time it works. Other half not. No Kidding!

point = 1
do while not oRs.EOF
lastName(point) = oRs("lastName")
point = point + 1
ors.movenext
loop

When I run this on my ASP page in the VBScript section it just stops on the page and won't load anything under the point where the record set comes into play. If anyone knows why this is happening, you'll save me from insanity.
 
I think the problem is on your "lastName" variable.
If you want to get an array value, you have to "dim" first, your variable,

Dim lastName()
point = 1
do while not oRs.EOF
lastName(point) = oRs("lastName")
point = point + 1
ors.movenext
loop

result will be : lastName(1),lastName(2)...

or you can get other variable
point = 1
do while not oRs.EOF
lastName&point = oRs("lastName")
point = point + 1
ors.movenext
loop

result will be: lastName1, lastName2, ...

-aliahmad dot net-
 
Thanks for looking into this. I forgot to mention some items. The array lastName I created dynamically at the top with a

Dim lastName()

then ran a loop through the database with a counter and redimensioned the array with the counter variable.

ReDim lastName(i)

Now I just want to loop through and place the items from the database into the array elements. One more thing. I believe the code you wrote to be solid and correct because that is what I was using too. Unfortunatly it wouldn't work on my ASP page for some reason or another.
 
do you have earlier in your code:

oRs.movefirst

if not, you may be getting weird results coz it's starting in the middle as opposed to the beginning.
hth
mb
 
Yup, I do have oRs.movefirst above it. I'm going to go buy a VBscript book to figure this one out.
 
How do I work with databases (vbscript won't accept server.createobject("adodb.connection")) in html and not asp? I use angelfire.com for my webpage and they do not allow asp pages on their site.
 
JohnAlex:

As far as I know, you need to be able to do server-side programming to be able to work with data bases - and this is usually not allowed by ISPs "for security reasons".

However, although your ISP (angelfire) doesn't allow Active Server Pages (ASP) scripts, they might support PHP scripts (written in Perl, rather than Visual Basic Script) - it depends on what server platform they use...

If this doesn't work, you might consider finding another ISP, although it might cost you (more) money to find one that hosts ASP pages. A simple search for "free ASP site hosting" came up with several alternatives, such as (which I had never heard about before) - just look around and see if you find something that fits your needs!

However, if you "only" want to play around with the programming for your own entertainment/training, try installing Personal WebServer (PWS) or Internet InformationServer (IIS) on your own PC - this allows you to work locally.

DrMaggie
---------
"Those who don't know the mistakes of the past won't be able to enjoy it when they make them again in the future."
— Leonard McCoy, MD (in Diane Duane's Doctor's Orders)
 
About the only things available for client-side use are Internet Explorer's Tabular Data Control and (I think) an XML data control of some sort.

TDC is installed with IE.

What TDC allows you to do is use ADO recordsets and data binding in your DHTML page to get access to a text file on the server. The text file is in a delimited text format, using commas, tabs, or what have you.

The text file is read-only of course, but TDC permits you to make a very interactive web page. For small amounts of information (less than 25K) TDC is quite responsive.

You can search on keys, filter on values, sort, and do just about anything a recordset can do. You can use data-bound tables and a TDC to make a pretty interactive, pageable tablular display of information.

I've even used data-bound tables and the MSChart control with TDC to display things like web-page usage week by week for an ASP information retrieval application (internal vs. external users by hour by day, hits vs. misses by hour by day). Of course the delimited text file containing the stats was created "behind the scenes" by server log analysis.

You can find out more about TDC by going to and searching on TDC and "tabular data control" there.

I don't know much about the XML data control, but I think this was the same idea, just using an read-only XML file instead of delimited text.

The other reason ADO exists on the client side at all has to do with two other technologies:

* Remote Data Service - an IIS feature that allows IIS to mediate in database access by a client page, to a database on the server. Most sites lock this down because there are a few hacker exploits related to it. Also it requires IIS at the server - and I don't think it works with Access (you need a client/server DB like SQL Server - not a file DB like Access).

* HTML Applications (or HTAs). This is an application made up of DHTML that can run as a local application - just like an EXE on the user's machine. Most of the security restrictions are lifted for HTAs, allowing your HTA application to freely access files and databases on the local machine. There are DHTML applications where the file ends in .HTA instead of .HTM
 
dilettante:

That's a nice HTA example you pointed to, there - but did I understand correctly that the client side has to use IE for it to work? In that case, they would unfortunately be of no use to me in my work, since most of the people using my applications (scientists at research institutes) use Linux as their only platform :(

drmaggie
---------
"Those who don't know the mistakes of the past won't be able to enjoy it when they make them again in the future."
— Leonard McCoy, MD (in Diane Duane's Doctor's Orders)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top