edderic
Programmer
- May 8, 1999
- 628
I am a textfile of 8 Mb with line records,if The line = "#CHLI" then the next 40 lines are = 40 database fields and insert to the database (Access).
In total 20.000 records with 40 fields to insert,the code is place to backgroundworker buth de insert is 1 hour to do complete !!!
The code :
If txtBestand.Text = Nothing Then Exit Sub
Dim fiFileHolder As FileInfo = New FileInfo(txtBestand.Text)
Dim srReadFile As StreamReader = fiFileHolder.OpenText()
Dim strInput As String
Dim LineCnt As Integer = 0
da.Fill(ds, "Artikelen")
Dim ipos As Integer = 0
Try
Do
strInput = srReadFile.ReadLine
If strInput <> "#CHLI" Then GoTo verder
Select Case strInput
Case "#FIN"
Exit Do
Case "#CHLI"
DatRij = ds.Tables("Artikelen").NewRow
For LineCnt = 0 To 46
If LineCnt = 0 Then
LineCnt = 1
End If
strInput = srReadFile.ReadLine
DatRij(LineCnt) = strInput
Next
ds.Tables("Artikelen").Rows.Add(DatRij)
da.Update(ds, "Artikelen")
End Select
verder:
Loop Until strInput Is Nothing
srReadFile.Close()
cmdLees.Enabled = True
cmdImport.Enabled = False
Catch ex As Exception
If oledbCon.State = ConnectionState.Open Then oledbCon.Close()
srReadFile.Close()
End Try
Eric De Decker
In total 20.000 records with 40 fields to insert,the code is place to backgroundworker buth de insert is 1 hour to do complete !!!
The code :
If txtBestand.Text = Nothing Then Exit Sub
Dim fiFileHolder As FileInfo = New FileInfo(txtBestand.Text)
Dim srReadFile As StreamReader = fiFileHolder.OpenText()
Dim strInput As String
Dim LineCnt As Integer = 0
da.Fill(ds, "Artikelen")
Dim ipos As Integer = 0
Try
Do
strInput = srReadFile.ReadLine
If strInput <> "#CHLI" Then GoTo verder
Select Case strInput
Case "#FIN"
Exit Do
Case "#CHLI"
DatRij = ds.Tables("Artikelen").NewRow
For LineCnt = 0 To 46
If LineCnt = 0 Then
LineCnt = 1
End If
strInput = srReadFile.ReadLine
DatRij(LineCnt) = strInput
Next
ds.Tables("Artikelen").Rows.Add(DatRij)
da.Update(ds, "Artikelen")
End Select
verder:
Loop Until strInput Is Nothing
srReadFile.Close()
cmdLees.Enabled = True
cmdImport.Enabled = False
Catch ex As Exception
If oledbCon.State = ConnectionState.Open Then oledbCon.Close()
srReadFile.Close()
End Try
Eric De Decker