Click here to Skip to main content
15,886,588 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
I found a code for reading a Excel file using OLEDB.
Read Data from Excel using OLEDB in VB.NET 2005 [^]
VB
Try
    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:\testfile.xls'; " _
     "Extended Properties=Excel 8.0;")
    MyCommand = New System.Data.OleDb.OleDbDataAdapter _
        ("select * from [Sheet1$]", MyConnection)
    MyCommand.TableMappings.Add("Table", "TestTable")
    DtSet = New System.Data.DataSet
    MyCommand.Fill(DtSet)
    DataGridView1.DataSource = DtSet.Tables(0)
    MyConnection.Close()
Catch ex As Exception
    MsgBox(ex.ToString)
End Try


The above code displays all data from Excel File. My question is how to put the Where Statement in the sql command. I just try using the header but it doesn't work.
Posted
Updated 16-Nov-11 23:07pm
v2

1 solution

You should be able to use the Select method[^] to filter out records.
 
Share this answer
 
Comments
hyderaliomr 19-Jun-13 6:38am    
HOW TO FILTER THE QUERY RESULT WITH WHERE CONDITION ?

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