最后 查找和修改Excel连接字串 解决
#region 读Excel
private void fnReadExcel(string strFileName ,string strSheetName,string strColumnName ,out DataSet dsData)
{
//strColumnName = " * ";
string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source =" + strFileName + ";Extended Properties = 'Excel 8.0;HDR=Yes;IMEX=1;'";
OleDbConnection oleConnection = new OleDbConnection(strConnection);
try
{
oleConnection.Open();
string strCommondText = "SELECT " + strColumnName + " FROM [" + strSheetName + "]";
DataSet dsRead = new DataSet();
OleDbDataAdapter oleAdper = new OleDbDataAdapter(strCommondText, oleConnection);
oleAdper.Fill(dsRead);
dsData = dsRead;
}
catch (System.Exception ex)
{
//throw new ApplicationException("读取数据源文件时出错");
dsData = null;
}
finally
{
oleConnection.Close();
}
}
#endregion