Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vbscript step through SQL results

Posted on 2009-07-09
3
Medium Priority
?
206 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 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