Read Text file, CSV file to DataGridView
Tháng Chín 12, 2008 at 1:02 sáng Để lại phản hồi
Public Sub ReadCSVFile(ByVal sFolder As String, ByVal sFileName As String, ByVal MyDGV As DataGridView)
Dim ConnectionString, CommandText As String
Dim Command As New OleDb.OleDbCommand
Dim da As New OleDb.OleDbDataAdapter(Command)
Dim myMainDataset As New DataSet
Dim BindSource As New BindingSource
ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & sFolder & “;Extended Properties=’text;HDR=Yes;FMT=Delimited’”
Dim Conn As New OleDb.OleDbConnection(ConnectionString)
CommandText = “select * from ” & “[" & sFileName & "]“
Conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
Command = New System.Data.OleDb.OleDbCommand(CommandText, Conn)
Conn.Open()
da = New OleDb.OleDbDataAdapter(CommandText, Conn)
myMainDataset = New DataSet
‘ fill dataset
da.Fill(myMainDataset, “MyTable”)
Conn.Close()
BindSource.DataSource = myMainDataset.Tables(“MyTable”)
‘datatabel(1) = myMainDataset.Tables(“MyTable”)
MyDGV.DataSource = BindSource
End Sub
Entry filed under: VB.NET. Tags: .
Trackback this post | Subscribe to the comments via RSS Feed