Solved

vbscript step through SQL results

Posted on 2009-07-09
3
199 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 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