Results 1 to 3 of 3

Thread: How to move to first record in my data reader

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    How to move to first record in my data reader

    I have the following code....

    VB Code:
    1. commSQL.Connection = cn
    2.                 commSQL.CommandText = "Select Stores From EmpStores_View Where " & _
    3.                 "LoginName = '" & Request.Cookies("LoginName").Value & "' Order By Stores"
    4.                 datRead = commSQL.ExecuteReader
    5.  
    6.                 strDistStores = ""
    7.                 Do While datRead.Read
    8.                     If strDistStores.Trim() = "" Then
    9.                         strDistStores = "And (Location = '" & _
    10.                         datRead.Item("Stores") & "'"
    11.                     Else
    12.                         strDistStores += " Or Location = '" & _
    13.                         datRead.Item("Stores") & "'"
    14.                     End If
    15.                 Loop
    16.                 strDistStores += ")"

    Now when I'm done here, I want to bind this same datasource to a combo box.

    What I don't know how to do is get to the first record after I run it through my loop.

    Thanks
    David Wilhelm

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    A datareader is a one shot deal. Once you go through it your done. I don't think you can read it again and you can't go backwards. You might want to return a dataset, or use the datareaders next results and do a second query in your stored procedure.

    Also remember that your datareader is connected - so you want to close it as soon as possible to release the open connection to the database. It is also readonly.

  3. #3
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Datareader is forward-only, read-only. If you are wanting to navigate through the records you'll need to use a DataSet.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width