Solved

vbscript step through SQL results

Posted on 2009-07-09
3
196 Views
Last Modified: 2012-05-07
The attached code properly displays the message box for the first record that matches the criteria, however it then just repeats the messagebox for the same record indefinitely.  I've used a similar setup before, but it was ASP.  This is straight VBS and I must be missing something simple.
	counter = 0

	limit = 5

 

	Dim cConnection

	Set cConnection = CreateObject("ADODB.Connection")

	

	//setting variables here for connection string, username, password.

 

	cConnection.Open DBConString,DBUser,DBPass

	SQLstmt = "SELECT field1, field2 from Table1 WHERE Field1 IS NULL"

	Set RS = cConnection.Execute(SQLstmt)

	

	while (not RS.EOF) AND (counter < limit)

		msgbox("Field1: " & RS.Fields.Item("field1").value)

		//do other stuff

		counter = counter + 1

		RS.Movenext()

	wend

Open in new window

0
Comment
Question by:Cerixus
  • 2
3 Comments
 
LVL 8

Expert Comment

by:stefanx
ID: 24817840
Looks fine to me, so it must be something with the RS.MoveNext() ?
Maybe just make it RS.MoveNext without the parentheses ?
0
 
LVL 1

Author Comment

by:Cerixus
ID: 24817867
No, it's apparently because I'm using ADODB.Connection and need to define and use a recordset... though I'm not entirely sure how to get to that point using a DSNless connection.
0
 
LVL 1

Accepted Solution

by:
Cerixus earned 0 total points
ID: 24818063
:facepalm:

In that whole //do other stuff section I had a function that was doing a database insert.  Stupidly, I was using RS for the recordset name.  Changed it to RS2 and now everything is working.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now