Imports Data from XLS file to DataGridView VB 2005
Tháng Chín 11, 2008 at 1:59 sáng Để lại phản hồi
I have XLS file which have format
| Adress | Name | Adress | Name | Adress | Name |
| Adr1 | Name1 | Adr2 | Name2 | Adr3 | Name3 |
| Adr4 | Name4 | Adr5 | Name5 | Adr6 | Name6 |
this data is read and input DataGridView which have format
| Adress | Name |
| Adr1 | Name1 |
| Adr2 | Name2 |
| Adr3 | Name3 |
| Adr4 | Name4 |
| Adr5 | Name5 |
| Adr6 | Name6 |
Dim strConnectionString As String = String.Empty
strConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\FILES\Test.xls;Extended Properties=”"Excel 8.0;HDR=No;IMEX=1″”"
Dim cnCSV As New OleDbConnection(strConnectionString)
cnCSV.Open
Dim cmdSelect As New OleDbCommand(“SELECT F1, F2 FROM [Sheet1$] union (SELECT F3, F4 FROM [Sheet1$] union SELECT F5, F6 FROM [Sheet1$])“, cnCSV)
Dim daCSV As New OleDbDataAdapter
daCSV.SelectCommand = cmdSelect
Dim dtCSV As New DataTable
daCSV.Fill(dtCSV)
cnCSV.Close
Me.dataGridView1.DataSource = dtCSV
Entry filed under: VB.NET. Tags: .
Trackback this post | Subscribe to the comments via RSS Feed