Hi All,
I have the following file, with blank row after every section:
I want to insert into a database starting from a certain row /e.g. "Country - Levski;Team oper;A;E1914;BGR.BGN - LV - 19140101;"/ until it reach the blank row and I am using that code:
Actually it is working, but at the end it gives me an error "Index was outside the bounds of the array". I am pretty sure that is because of the empty line at the end. Could you please advise how can I handle this?
Thanks in advance!
I have the following file, with blank row after every section:
Code:
Country - Levski;Team oper;A;E1914;BGR.BGN - LV - 19140101;
Napravlenie kategoria;Validno ot;Vremevi paket. referencia;obekt na taksuvane;razdeliane;vremeva razlika;smetka vatreshna;cena;ime na paketa;nomer;cena druga;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
Country - Levski;Team oper;A;E1914;BGR.BGN - LV - 19140101;
Napravlenie kategoria;Validno ot;Vremevi paket. referencia;obekt na taksuvane;razdeliane;vremeva razlika;smetka vatreshna;cena;ime na paketa;nomer;cena druga;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
BGM - MF;2000.10.10;BGR.BGN - nenatovaren;D;S;natovaren 7_21;;2*1[C]~0.2;nenatovaren 21_7;;2*2[T]~0.1;
Code:
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim path As String = "D:\tariff1.txt"
Dim line As String
'Dim row As String
Dim sr As StreamReader = New StreamReader(path)
Do While sr.Peek() >= 0
'MsgBox(sr.ReadLine())
line = sr.ReadLine()
If line = "Country - Levski;Team oper;A;E1914;BGR.BGN - LV - 19140101;" Then
Do Until line = ""
line = sr.ReadLine()
Dim stat As String = "BGRVA"
Dim parts() As String = line.Split(Convert.ToChar(";"))
'MsgBox(parts(1))
conn.Open()
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandText = "insert into table1 values ('" & parts(0) & "','" & parts(1) & "','" & parts(2) & "','" & parts(3) & "','" & parts(4) & "','" & parts(5) & "','" & parts(6) & "','" & parts(7) & "','" & parts(8) & "','" & parts(9) & "','" & parts(10) & "')"
cmd.CommandType = CommandType.Text
cmd.ExecuteNonQuery()
'cmd.Dispose()
'conn.Dispose()
conn.Close()
Loop
End If
Loop
sr.Close()
End Sub
Thanks in advance!