Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Same row returning multiple times

Author  Topic 

ssholl
Starting Member

2 Posts

Posted - 2012-09-17 : 09:34:54
HI All,

Something weird is going on with my query, im connecting to sql through VBS, my table looks like the below
FirstName
Surname
Department

when i run the below query i get each row 3 times, if i add another field i get it 4 times etc, it returns the same row as many times there are columns.
my statement is below

set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=Localhost\sqlexpress;Trusted_Connection=Yes;Initial Catalog=Starters;User ID=MYUSERNAME;Password=MYPASSWORD;"

Set rs = CreateObject("ADODB.RecordSet")
rs.Open "select * from NewStarters" , conn

For each x in RS.Fields
FirstName =RS.Fields(0).Value
Wscript.echo FirstName

Next


rs.close
conn.close


any ideas why

ssholl
Starting Member

2 Posts

Posted - 2012-09-17 : 09:53:29
Ok ive slightly updates it and get something different

while rs.EOF=False
For each x in RS.Fields
FirstName = rs.fields("FirstName")
wscript.echo FirstName
Surname = rs.fields("Surname")
Wscript.echo Surname
Description = rs.fields("Department")
Wscript.echo Department


Next

Wend

rs.close
conn.close
this will give this error
(9, 2) ADODB.Field: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
If i move the NEXT to below Wend, it just repeats over and over


Go to Top of Page
   

- Advertisement -