Code:
' Imports System.IO
' Imports System.Runtime.InteropServices
Private Structure RecordType
Public datCallingDateTime As Date
Public lngTransTime As Long
Public intTkNo As Integer
Public intServiceNo As Integer
Public intCounterNo As Integer
Public intApplicationNo As Integer
End Structure
Dim handle As GCHandle
Dim ptr As IntPtr
Dim Record As RecordType
Dim Buffer(Len(Record) - 1) As Byte
Dim theFile As New FileStream("d:\path\filename.L", FileMode.Open, FileAccess.Read)
Do Until theFile.Position >= theFile.Length
' Read one record into Buffer array
theFile.Read(Buffer, 0, Buffer.Length)
' Copy Buffer into Record structure
handle = GCHandle.Alloc(Buffer, GCHandleType.Pinned)
ptr = handle.AddrOfPinnedObject()
Record = DirectCast(Marshal.PtrToStructure(ptr, GetType(RecordType)), RecordType)
handle.Free()
' -- Insert values of Record structure into database
Loop
theFile.Close()
Bookmarks