Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"End of File" needing some help here...

Status
Not open for further replies.

herb8

Programmer
Sep 4, 2001
45
US
Hello All,
I'm importing a fixed length record file. And am wondering if there is any easy way to tell if im at the end of the file like there was in .vb 6 using .eof ?
If anyone can help me out I would appreciate it.
Thanks in advance,
Matt
 
This is one way using the reader object

Public Function EmployeeList(ByVal employeeid As String)

Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim Reader As OleDbDataReader
Dim strSQL As String
dim EmployeeName, phone, email as string

Try
strSQL = "SELECT EmployeeName, phone, email FROM Employee"
strSQL += "WHERE employeeid = " & employeeid

myConnection = New OleDbConnection(ConnectionString)
myConnection.Open()
myCommand = New OleDbCommand(strSQL, myConnection)
Reader = myCommand.ExecuteReader()

Do While Reader.Read()

employeeName = Reader.Item("EmployeeName").ToString()
phone = Reader.Item("phone").ToString()
email = Reader.Item("email").ToString()

Loop

Catch e As OleDbException
_myLocalError += "[Error Source]: " + e.Source + "[Error Message]: " + e.Message
Exit Function
Catch ex As Exception
_myLocalError += "[Error Source]: " + ex.Source + "[Error Message]: " + ex.Message
Exit Function
Finally
Reader.Close()
myConnection.Close()
myConnection.Dispose()
myCommand.Dispose()
End Try



End Function
 
You can use the peek method of the StreamReader:
-----------------------------------------------
Dim SR As New IO.StreamReader("YourFileName")
Dim Inline As String
While (SR.Peek() > -1)
Inline = SR.ReadLine()
'Do whatever here
End While
-----------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top