Can you use a datareader multiple times?
Printable View
Can you use a datareader multiple times?
Close() it, reopen it, and Read() it again!
I tried that and it still fails. I must be having a different problem then.
Thanks.
Maybe you have to reassign it with the ExecuteReader() method, because it is a forward-only IO object.
This is some sample code of how I might do it:
VB Code:
MyODBCConn = New Microsoft.Data.Odbc.OdbcConnection(myConnectionString) For MyI = 0 To UBound(mPrinters) MyFiles = System.IO.Directory.GetFiles(LogDir & mPrinters(MyI).pName & "\temp\", mPrinters(MyI).pLogNameHint & "*") For MyJ = 0 To 0 'UBound(MyFiles) 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)) & "' " MyODBCConn.Open() MyODBCCommand = New Microsoft.Data.Odbc.OdbcCommand(strSQL, MyODBCConn) MyODBCReader = MyODBCCommand.ExecuteReader(CommandBehavior.CloseConnection) 'MsgBox(MyODBCReader.GetName(0).ToString) If MyODBCReader.Read = True Then 'move file to main MyMovePath = LogDir & mPrinters(MyI).pName & "\" & System.IO.Path.GetFileName(MyFiles(MyJ)) System.IO.File.Move(MyFiles(MyI), MyMovePath) End If MyODBCReader.Close() MyODBCCommand.Dispose() MyODBCConn.Close() Me.Text = MyI & "_" & UBound(mPrinters) & " " & MyJ & "_" & UBound(MyFiles) Application.DoEvents() Next Next MyODBCConn.Close() MyODBCConn.Dispose()