Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8961095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:48:30+00:00 2026-06-15T15:48:30+00:00

I am working on fixing a C# project which uses an Excel sheet with

  • 0

I am working on fixing a C# project which uses an Excel sheet with data definition to create a .fmt file used by a bulk insert in SQL Server.

My issue is that the Excel files sometimes have blank rows at the bottom and the C# parser I am working on will detect a number of rows superior to the actual number of rows containint data definition.

The fmt file therefore has a larger number of rows on its second line and bulk insert throws an exception when it reaches the bottom and tries to read on.

For instance there are only 50 rows with data and 50 blank rows. The fmt file will have a 100 on its second line (the first line is for the SQL Server version). Line 3 to 52 are the 50 lines of data definition. When bulk insert tries to reach line 53, it returns a number of column exception.

The C# parser uses Ace OleDB 12 to connection to the Excel 97 format file.

The SQL is:

var commandText = string.Format("SELECT * FROM [{0}$]", SpreadSheetName);

I have tried to add a WHERE clause to the SQL code to only select rows with a non-empty “A” column, but this does not work.

SELECT * FROM [{0}$] WHERE [A] <> ''

Is there a way the command text can be enhanced with some SQL code to only extract rows of data out of Excel where a certain condition is met?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:48:31+00:00Added an answer on June 15, 2026 at 3:48 pm

    If your spreadsheet has headers (I don’t mean Excel’s “A”, “B”, etc. column headers), then you can use those in the conditions. You’ll need to specify it in the connection string when you instantiate your OleDbConnection.

    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
    

    Then you can execute SQL along the lines of

    string SQL = "SELECT * FROM [Sheet1$] WHERE [Name] <> ''";
    

    If your spreadsheet does not have headers you can still use a WHERE clause, but you must reference the columns by “F1”, “F2”, etc. and set your connection string to not use headers

    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=\"Excel 8.0;HDR=NO;\"";
    string SQL = "SELECT * FROM [Sheet1$] WHERE [F1] <> ''"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on fixing a c# codebase which does not have a
I am working on a TcpClient Asynchronous requesting WPF project. In which I have
I'm trying to create a simple flex4 project which involves some timers that trigger
I was working on a project and there is bulk e-mail sending part of
I'm working on a cocoa project. My project uses a preferences menu, and includes
I'm working in a project I used to do things like: hg grep TODO
I am working in a Ruby on Rails project which has implemented authentication mechanism
http://jsfiddle.net/nWqYL/2/embedded/result/ I've been working on fixing some issues with this prototype site. Myself and
Working on the problems on Project Euler to try to learn Clojure. I'm on
I'm working on a project left by a programmer in our company i'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.