This was a solution given by Sancler (Roger) ; which is really fast in getting a CSV file into a datagrid ; unfortunately I have csv files that are created by a legacy program that does not have the .txt extention; what do I change in this code to make these files laod (File names are 0011.1, 0111.2 1111.2 etc). If I use these file names the system reports read only error . . . I am using VB STUDIO (2005)
One more thing how can you get a progess bar to display . . where should the hook be?
This is the code:-
Imports System.Data.OleDb
'at the start and
Private ds As New DataSet
'and
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As String = "Provider=Microsoft.Jet.OL
EDB.4.0;" & _
"Data Source=" & "C:\" & ";" & _
"Extended Properties=""Text;HDR=NO;F
MT=Delimit
ed"""
Dim conn As New System.Data.OleDb.OleDbCon
nection(cn
)
Dim da As New System.Data.OleDb.OleDbDat
aAdapter("
SELECT * FROM trial.txt", conn)
ds.Tables.Clear()
DataGrid1.DataSource = Nothing
Dim ticks As Long = Now.Ticks
da.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
Console.WriteLine((Now.Tic
ks - ticks) / TimeSpan.TicksPerMilliseco
nd & " milliseconds")
End Sub
Sancler's comments :-
You will also need to add a text file file called Schema.Ini to the same directory as your tab-delimited text data file. For the purposes of this demo, the directory is C:\ and the data file is called trial.txt. Change those values as necessary above and in the following, which is what the Schema.Ini file should contain
[trial.txt]
ColNameHeader=False
Format=TabDelimited
CharacterSet=ANSI
Just a warning. Don't use "text" as your data file's name (for some reason, this approach doesn't seem to like that) but do use .txt as its extension.
Start Free Trial