日期:2014-05-17 浏览次数:20843 次
foreach (string FilePath in strFiles) { OleDbConnection dbcon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0"); try { if (dbcon.State == ConnectionState.Closed) { dbcon.Open(); } for (int i = 0; i < TableList.Count; i++) { string dtname = TableList[i].ToString(); try { OleDbCommand cmd = new OleDbCommand("select * from [" + dtname + "$]", dbcon); OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); table = new DataTable(dtname); adapter.Fill(table); ds.Tables.Add(table); } catch (Exception exp) { MessageBox.Show(exp.Message); } } } finally { if (dbcon.State == ConnectionState.Open) { dbcon.Close(); } } }