这是我打开 Excel 文件和读取数据的代码,一切正常,但我想在读取 Excel 文件后关闭,我该怎么做?我尝试Dispose
了这个对象,但没有帮助。
public static DataTable ExcelWorkbook(string workbookName)
{
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", FILENAME);
string query = String.Format("select * from [{0}$]", workbookName);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
dataAdapter.Dispose();
DataTable myTable = dataSet.Tables[0];
if (myTable != null)
return myTable;
return null;
}