Click here to Skip to main content
14,927,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an excel sheet named"Ispis" with 2 tables each having 6 columns
Before Table1 are some data and also there are some data between Table1 and Table2
Table1 with headers starts at B16:G16 and ends at B62:G62
Table2 with headers starts at B91:G16 and ends at B118:G118
I want to load Table1 to DataGridview1 and Table2 to Datagridview2
My code does not work because there are some data before table1
My Code
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\korisnik\Desktop\" & File.Text & "';Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select Sifra, Amount from [Ispis$];", MyConnection)
MyCommand.TableMappings.Add("Table", "")
DtSet = New System.Data.DataSet
DataGridView1.DataSource = DtSet.Tables(0)

Please help
Updated 18-Jan-15 13:09pm

1 solution

You can include the range as part of the sheet name. Something like:

from [Ispis$B16:G62]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900