Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

Select specific rows within Excel

I have the following select

MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)

How would I configure the select statement to start on a specific row (say row 14) and go until the there were no more rows with data?

0
Jedidia
Asked:
Jedidia
  • 2
1 Solution
 
Wayne Taylor (webtubbs)Commented:
You can do that like this....

    MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$14:65536]", MyConnection)

Wayne
0
 
JedidiaAuthor Commented:
Hi Webtubbs - This works great for starting at row 14, but is there also a way to identify the last row with data and the select stops at that row?

I am passing this to a datatable and it adds ALOT of empty rows in my datatable..:)
0
 
Wayne Taylor (webtubbs)Commented:
You can inform the DataAdapter to not include blank rows by using a WHERE clause....

    MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$14:65536] WHERE F1 <> ''", MyConnection)

...where F1 is the first column. The second column would be F2, the third F3, etc.

Wayne
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now