01.
Private
Sub
btupload_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
btupload.Click
02.
Dim
myConnectionString
As
String
=
"server=.\SQLEXPRESS;"
& _
03.
"integrated security=sspi;database=logfileSQL"
04.
Dim
myConnection
As
SqlConnection =
New
SqlConnection(myConnectionString)
05.
Dim
csvInputFile
As
String
=
"C:\logfile_mysql.csv"
06.
07.
Dim
cmd
As
SqlCommand = myConnection.CreateCommand()
08.
09.
Dim
dt
As
New
DataTable()
10.
Dim
line
As
String
=
Nothing
11.
Dim
i
As
Integer
= 0
12.
Using sr
As
StreamReader = File.OpenText(csvInputFile)
13.
line = sr.ReadLine()
14.
Do
While
line IsNot
Nothing
15.
Dim
data()
As
String
= line.Split(
","
c)
16.
If
data.Length > 0
Then
17.
If
i = 0
Then
18.
For
Each
item
In
data
19.
dt.Columns.Add(
New
DataColumn())
20.
Next
item
21.
i = 1
22.
End
If
23.
Dim
row
As
DataRow = dt.NewRow()
24.
row.ItemArray = data
25.
dt.Rows.Add(row)
26.
End
If
27.
line = sr.ReadLine()
28.
dgv1.DataSource = dt
29.
Loop
30.
31.
End
Using
32.
myConnection.Open()
33.
Dim
bc
As
New
SqlBulkCopy(myConnection)
34.
MsgBox(dt.Rows.Count)
35.
bc.BatchSize = dt.Rows.Count
36.
bc.DestinationTableName =
"transactionsanalyzer"
37.
bc.WriteToServer(dt)
38.
bc.Close()
39.
myConnection.Close()
40.
dgv1.DataSource = dt
41.
End
Sub