Do While Not - syntax

S

shank

I want to update multiple rows in an SQL table.
Presently, it's populating all rows with the same data based on the first
row.
It's not looping through all records one at a time.
Is this the correct syntax.

<%
rsOD 'recordset up here
%>

<%
Dim DataConn1
Set DataConn1 = Server.CreateObject("ADODB.Connection")
DataConn1.Open MMSTRING
Do While Not rsOD.EOF
'SQL UPDATE statement here
DataConn1.Execute(SQL)
rsOD.MoveNext
Loop
%>

thanks!
 
E

Egbert Nierop \(MVP for IIS\)

shank said:
I want to update multiple rows in an SQL table.
Presently, it's populating all rows with the same data based on the first
row.
It's not looping through all records one at a time.
Is this the correct syntax.

<%
rsOD 'recordset up here
%>

<%

Dim DataConn1
Set DataConn1 = CreateObject("ADODB.Connection")
DataConn1.Open MMSTRING

Do Until rsOD.EOF
'SQL UPDATE statement here
are you sure you create the SQL Update statement using
rsOD("somefield") ???

DataConn1.Execute SQL,, 128 'this is more efficient
rsOD.MoveNext
Loop
rsOD.Close

%>
 
M

Mike Brind

shank said:
I want to update multiple rows in an SQL table.
Presently, it's populating all rows with the same data based on the first
row.

This normally happens if you forgot to add a WHERE clause in your SQL
statement, although it's usually the last row that you finally see.
However, how do you know it's updating based on the first row? Do you have
an ORDER BY clause for your rsOD?
It's not looping through all records one at a time.
Is this the correct syntax.

<%
rsOD 'recordset up here
%>

<%
Dim DataConn1
Set DataConn1 = Server.CreateObject("ADODB.Connection")
DataConn1.Open MMSTRING
Do While Not rsOD.EOF
'SQL UPDATE statement here
DataConn1.Execute(SQL)
rsOD.MoveNext
Loop
%>

Given what I said further up, you should have included the SQL statement you
are using, especially as the syntax for looping through a recordset is
correct in your example. One way to test if the loop is executing is like
this:

Dim i : i=1
Do While Not rsOD.EOF
'SQL UPDATE statement here
Response.write i & "<br>"
DataConn1.Execute(SQL)
rsOD.MoveNext
i=i+1
Loop

If none of what I've said helps you, come back to us with your SQL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top