Dim objAdapter1 As New OleDbDataAdapter
Dim objDataset1 As New DataSet
Dim row As Integer = 0
objAdapter1.Dispose()
objDataset1.Clear()
dgv1.DataSource = Nothing
dgv1.Refresh()
If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then
Try
Dim a As New FileInfo(OpenFileDialog1.FileName)
Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & a.DirectoryName
Dim objConn As New OleDbConnection(sConnectionString)
objConn.Open()
Dim objCmdSelect As New OleDbCommand("SELECT Name , Bytes , Packets , BitsPerSecond , PacketsPerSecond ,BytesPercentage , PacketsPercentage FROM " & a.Name, objConn)
objAdapter1.SelectCommand = objCmdSelect
objAdapter1.Fill(objDataset1, "test")
dgv1.DataSource = objDataset1.Tables(0).DefaultView
objConn.Close()
Catch ex As Exception
End Try
Try
dgv1.AllowUserToAddRows = False
For Each DataRow As DataGridViewRow In dgv1.Rows
Dim z As String = dgv1.Rows(row).Cells("Name").Value
Dim b As String = dgv1.Rows(row).Cells("Bytes").Value
Dim c As String = dgv1.Rows(row).Cells("Packets").Value
Dim d As String = dgv1.Rows(row).Cells("BitsPerSecond").Value
Dim y As String = dgv1.Rows(row).Cells("PacketsPerSecond").Value
Dim f As String = dgv1.Rows(row).Cells("BytesPercentage").Value
Dim g As String = dgv1.Rows(row).Cells("PacketsPercentage").Value
connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\AnalyzerDb.mdb")
connection.Open()
cmd = New OleDbCommand("INSERT INTO ProtocolExistUsed VALUES('" & z & "','" & b & "','" & c & "','" & d & "','" & y & "','" & f & "','" & g & "')", connection)
cmd.ExecuteNonQuery()
row += 1
connection.Close()
Next
Catch
MsgBox(ErrorToString, vbCritical, "Search")
End Try
Else
MsgBox("Please insert Data. ", MsgBoxStyle.Information, "error")
End If
The above is a source code to load a csv file to a data grid view then save it into the access 2003 database. But this code only can let the user each time to load 1 file into dgv and save it. So my problem is can i make it to let user juz hit 1 button then the the system will load all the file into the dgv and save into the database according to Filename or File ID. Please help me and show me how to make it.Thanks.