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: .

Get XLS Sheet Name (VB2005) Save DataGridView to Text file,CSV file

Gửi phản hồi

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Thay đổi )

Twitter picture

You are commenting using your Twitter account. Log Out / Thay đổi )

Facebook photo

You are commenting using your Facebook account. Log Out / Thay đổi )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


 

Tháng Chín 2008
T2 T3 T4 T5 T6 T7 CN
« Tháng 8   Tháng 10 »
1234567
891011121314
15161718192021
22232425262728
2930  

Follow

Get every new post delivered to your Inbox.