Retriving EXCEL data

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
I'm trying retriving EXCEL data like following
I refered this link(How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET)
---------------------------------------------
Dim conn1 As New System.Data.OleDb.OleDbConnection(m_sConn1)
conn1.Open()
Dim cmd1 As New System.Data.OleDb.OleDbCommand("Select * From [EmployeeData$] WHERE id = 1", conn1)
Dim rdr As OleDbDataReader = cmd1.ExecuteReader


Do While rdr.Read()


Loop
rdr.Close()
conn1.Close()
---------------------------------------------
Without WHERE clause, it works well.
But, if I use WHERE condition(WHERE id = 1), can't retrieve data(can't go into Do While loop)
Does anybody have an idea to about this?
 
You can't use full SQL command set when reading Excel files as databases unfortunately. If you want to filter results you'll have to do so in the dataset/datatable (eg. using DataView) after data collection.
 
Dim dv As New DataView(dt) ' where dt is the table to which you are applying the filter

dv.RowFilter = "id = 1" ' assuming that your datatable column name is 'id'

It's been a while since I used one so I've assumed that the filter is inclusive. Obviously, if it's not, you'll need "id <> 1"
 

Latest posts

Back
Top