2 notes:
1) bad connection string:
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 8.0;")
Please, refer this:
http://www.connectionstrings.com/excel/[
^]
If you would like to connect to MS Excel 2007 (and higher) file, please use:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx; Extended Properties="Excel 12.0 Xml;HDR=YES";
For MS Excel 97-2003, please use:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls; Extended Properties="Excel 8.0;HDR=Yes;
2) bad command:
select * from [stulist.xlsx$]
Your command should refer to existing sheet:
select * from [Sheet1$]
So, if you would like to dynamically connect to any Excel file, you should
list all sheets in a workbook[
^] first.
By The Way: have a look at my tip:
How to: Get Data from Multiple Workbooks using One OleDbConnection?[
^]