Do While Loop (ASP.NET) not working

L

L. Oborne

I have this code working fine in Classic ASP but I get compile errors when I
try to run it as ASP.NET.

Do While NOT RS.EOF
If ...
Then...
Else...
End If
RS.MoveNext
Loop

It says that 'MoveNext' is not a member of
'System.Data.SqlClient.SqlDataReader'

Any suggestions?
 
K

Kyril Magnos

That is correct. You are thinking in old ASP ways, not ADO.NET

The correct way to do it would be:
(Forgive my VB.NET, wayyyy rusty!)

<pseudo-code>
Dim reader As SqlDataReader =
SqlCommand.ExecuteReader(CommandBehavior.Default)

Do While reader.Read()
If...
Then...
Else...
End If...
Loop
reader.Close()

HTH,

Kyril
-----Original Message-----
From: L. Oborne [mailto:none(at)none.ab]
Posted At: Wednesday, July 14, 2004 10:17 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Do While Loop (ASP.NET) not working
Subject: Do While Loop (ASP.NET) not working

I have this code working fine in Classic ASP but I get compile errors
when I
try to run it as ASP.NET.

Do While NOT RS.EOF
If ...
Then...
Else...
End If
RS.MoveNext
Loop

It says that 'MoveNext' is not a member of
'System.Data.SqlClient.SqlDataReader'

Any suggestions?
 
C

Craig Deelsnyder

L. Oborne said:
I have this code working fine in Classic ASP but I get compile errors when I
try to run it as ASP.NET.

Do While NOT RS.EOF
If ...
Then...
Else...
End If
RS.MoveNext
Loop

It says that 'MoveNext' is not a member of
'System.Data.SqlClient.SqlDataReader'

Any suggestions?
Use .NextResult instead

http://msdn.microsoft.com/library/d...temdatasqlclientsqldatareadermemberstopic.asp

note these are new 'structures' in ADO.NET (which replaced ADO); the
reader is basically like the old connected recordset, but there are
changes....
 
L

L. Oborne

Great, Thanks!

Also, is there a replacement for 'If Not RS.EOF Then' ?
..NET does not like 'EOF'
 
C

Craig Deelsnyder

L. Oborne said:
Great, Thanks!

Also, is there a replacement for 'If Not RS.EOF Then' ?
.NET does not like 'EOF'


L. Oborne wrote:

when I
Use .NextResult instead


http://msdn.microsoft.com/library/d...temdatasqlclientsqldatareadermemberstopic.asp

note these are new 'structures' in ADO.NET (which replaced ADO); the
reader is basically like the old connected recordset, but there are
changes....
Actually, I think you want the .Read() method that returns a boolean, I
gave you a different method:

http://msdn.microsoft.com/library/d...mdatasqlclientsqldatareaderclassreadtopic.asp

please see the documentation.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top