Click here to Skip to main content
15,889,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am openning an excel file using an OleDbConnection in c# in .NET Framework 3.5.
The connection string is:
C#
string mycon = "provider=Microsoft.Jet.OLEDB.4.0; data source=" + filePath + ";Extended Properties='Excel 8.0;IMEX=1';"


When I open this excel:
FirstName | MiddleName | LastName
---------------------------------
fname1    | m1         | lname1

And execute this query using OleDbCommand.ExecuteReader:
C#
"Select * FROM [Sheet1$] where F1='fname1' and F2='m1' and F3='lname1'"

It works well.


But when I change the excel into this:
FirstName | MiddleName | LastName
---------------------------------
fname1    |            | lname1

And execute a query using this:
C#
"Select * FROM [Sheet1$] where F1='fname1' and F2='' and F3='lname1'"

Or this:
C#
"Select * FROM [Sheet1$] where F1='fname1' and F2=null and F3='lname1'"

It yields no result.

I really need your help.
Thanks in advance.
Posted
Updated 7-Sep-11 18:42pm
v2

1 solution

Try this.
"Select * FROM [Sheet1$] where F1='fname1' and (F2='' or F2 is null) and F3='lname1'"
 
Share this answer
 

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