Results 1 to 5 of 5

Thread: Using a datareader multiple times

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    treehouse
    Posts
    106

    Using a datareader multiple times

    Can you use a datareader multiple times?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Close() it, reopen it, and Read() it again!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    treehouse
    Posts
    106
    I tried that and it still fails. I must be having a different problem then.

    Thanks.

  4. #4
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Maybe you have to reassign it with the ExecuteReader() method, because it is a forward-only IO object.
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  5. #5
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Using a datareader multiple times

    This is some sample code of how I might do it:

    VB Code:
    1. MyODBCConn = New Microsoft.Data.Odbc.OdbcConnection(myConnectionString)
    2.  
    3.  
    4.         For MyI = 0 To UBound(mPrinters)
    5.             MyFiles = System.IO.Directory.GetFiles(LogDir & mPrinters(MyI).pName & "\temp\", mPrinters(MyI).pLogNameHint & "*")
    6.             For MyJ = 0 To 0 'UBound(MyFiles)
    7.                 strSQL = "SELECT DISTINCT cms.print_history_log.log_file_name FROM cms.print_history_log WHERE cms.print_history_log.log_file_name = '" & mPrinters(MyI).pName & "\" & System.IO.Path.GetFileName(MyFiles(MyJ)) & "' "
    8.                 MyODBCConn.Open()
    9.                 MyODBCCommand = New Microsoft.Data.Odbc.OdbcCommand(strSQL, MyODBCConn)
    10.                 MyODBCReader = MyODBCCommand.ExecuteReader(CommandBehavior.CloseConnection)
    11.                 'MsgBox(MyODBCReader.GetName(0).ToString)
    12.                 If MyODBCReader.Read = True Then
    13.                     'move file to main
    14.                     MyMovePath = LogDir & mPrinters(MyI).pName & "\" & System.IO.Path.GetFileName(MyFiles(MyJ))
    15.                     System.IO.File.Move(MyFiles(MyI), MyMovePath)
    16.                 End If
    17.                 MyODBCReader.Close()
    18.                 MyODBCCommand.Dispose()
    19.                 MyODBCConn.Close()
    20.                 Me.Text = MyI & "_" & UBound(mPrinters) & " " & MyJ & "_" & UBound(MyFiles)
    21.                 Application.DoEvents()
    22.             Next
    23.         Next
    24.         MyODBCConn.Close()
    25.         MyODBCConn.Dispose()

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