Dear All
I am using a code to loop through excel files in a Directory using FolderBrowserDialog and it is working well but Slow, And I want to speed up the procedure by using OLEDB Connection , What I Discovered that the OLEDB is working well with one file having one path but when I tried to use it for looping for many files in a Directory it is failed
Here is my Code
Notice I tried to use Files or File But it Does not work either
Appreciate your informing me what is missing here or how can I use OLEDB for group of files
Thanks, Regards
Moheb Labib
I am using a code to loop through excel files in a Directory using FolderBrowserDialog and it is working well but Slow, And I want to speed up the procedure by using OLEDB Connection , What I Discovered that the OLEDB is working well with one file having one path but when I tried to use it for looping for many files in a Directory it is failed
Here is my Code
Code:
If FolderBrowserDialog1.ShowDialog = System.Windows.Forms.DialogResult.OK Then
Dim Directory = FolderBrowserDialog1.SelectedPath
Dim Files() As System.IO.FileInfo
Dim DirInfo As New System.IO.DirectoryInfo(Directory)
Files = DirInfo.GetFiles("*", IO.SearchOption.AllDirectories)
For Each File In Files
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" & Directory & "\" & "*.xls" & "'
;Extended Properties=Excel 8.0;")
MyCommand = New OleDbDataAdapter("select SN, BarMark, Diameter, Length, Quantity
,BBSName from [SCHEDULE$]", MyConnection)
MyCommand.TableMappings.Add("Table", "Test")
DtSet = New DataSet
MyCommand.Fill(DtSet)
DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
Next
End If
Appreciate your informing me what is missing here or how can I use OLEDB for group of files
Thanks, Regards
Moheb Labib