Do While Loop (ASP.NET) not working

Discussion in 'ASP .Net' started by L. Oborne, Jul 14, 2004.

  1. L. Oborne

    L. Oborne Guest

    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?
     
    L. Oborne, Jul 14, 2004
    #1
    1. Advertisements

  2. L. Oborne

    Kyril Magnos Guest

    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?
     
    Kyril Magnos, Jul 14, 2004
    #2
    1. Advertisements

  3. L. Oborne

    Marina Guest

    Yes - look up the documentation for the SqlDataReader class.
     
    Marina, Jul 14, 2004
    #3
  4. 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....
     
    Craig Deelsnyder, Jul 14, 2004
    #4
  5. L. Oborne

    L. Oborne Guest

    Great, Thanks!

    Also, is there a replacement for 'If Not RS.EOF Then' ?
    ..NET does not like 'EOF'
     
    L. Oborne, Jul 14, 2004
    #5
  6.  
    Craig Deelsnyder, Jul 14, 2004
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.