For Programmers: Free Programming Magazines  


Home > Archive > ASP > December 2006 > Do While Not - syntax









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Do While Not - syntax
shank

2006-12-04, 6:55 pm

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!


Egbert Nierop \(MVP for IIS\)

2006-12-04, 6:55 pm


"shank" <shank@tampabay.rr.com> wrote in message
news:uC17Kq6FHHA.1188@TK2MSFTNGP06.phx.gbl...
>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

%>

Mike Brind

2006-12-04, 6:55 pm


"shank" <shank@tampabay.rr.com> wrote in message
news:uC17Kq6FHHA.1188@TK2MSFTNGP06.phx.gbl...
>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.

--
Mike Brind


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com