Solved

vbscript step through SQL results

Posted on 2009-07-09
3
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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.

624 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