troubleshooting Question

Read Excel 2003 XLS file and query results

Avatar of marcuschang
marcuschangFlag for United States of America asked on
Programming.NET ProgrammingMicrosoft Excel
6 Comments1 Solution601 ViewsLast Modified:
I have been searching around but can't find anything to answer this. I'm trying to query data form excel xls file with a VB.Net winform to pass result for rest of app but I'm stuck here.

Dim con As New OleDbConnection
Dim cmd As New OleDbCommand
Dim total As Integer
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Reports\SOFL-mployee_Support.xls;Extended Properties=Excel 8.0"
cmd.Connection = con
 cmd.CommandText = "Select Count(Sr Id) from [SOFL-Employee_Support$] Where [Status]=Closed"
        con.Open()
        total = CInt(cmd.ExecuteScalar)
        con.Close()
        MsgBox(total)

Trying to read file, worksheet and query results. If I could just get data into msgbox I could take it from here, Problem with above code is in debug mode it just exits at con.Open no error, but might be something with my syntax. Done a few queries with sql but not much with oledb, unless there is a easier way.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros