/// <summary> /// 到数据库中查找表名 /// </summary> /// <param name="strPath">数据库名称,例如:"F:\\AccessMDB\\AccessMDB\\bin\\Debug\\AccessDB\\2008-1-25.mdb"</param> /// <returns>返回所有表的名称</returns> private DataTable GetTableName(string strPath) { //OleDbConnection connAcc = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + strPath + ";Jet OLEDB:Database Password=shkj;"); DataTable dtName = new DataTable(); try { if (connAcc == null || connAcc.ConnectionString == "") { connAcc = DAO.GetConnByPath(strPath); } if (connAcc.State == ConnectionState.Closed) { connAcc.Open(); } dtName = connAcc.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); } catch (Exception ex) { if (ex.Message.IndexOf("由于您和其他用户试图同时改变同一数据") != -1) { if (connAcc.State != ConnectionState.Closed) { connAcc.Close(); connAcc.Dispose(); connAcc = null; } try { string strfilenameTemp = strPath.Replace(".mdb", ".ldb"); if (File.Exists(strPath)) { File.Delete(strPath); } File.Delete(strPath); } catch { } } else if (ex.Message.IndexOf("不可识别的数据库格式") != -1) { //if (ErrorMessage != null) //{ // ErrorMessage(6020001, ex.StackTrace, "[AccessImport:GetTableName]", ex.Message); //} if (connAcc.State != ConnectionState.Closed) { connAcc.Close(); connAcc.Dispose(); connAcc = null; } try { string strfilenameTemp = strPath.Replace(".mdb", ".ldb"); if (File.Exists(strPath)) { File.Delete(strPath); } File.Delete(strPath); } catch { } } else { if (ErrorMessage != null) { ErrorMessage(6020001, ex.StackTrace, "[AccessImport:GetTableName]", ex.Message); } } } finally { if (connAcc.State != ConnectionState.Closed) { connAcc.Close(); } if (connAcc != null) { connAcc.Dispose(); connAcc = null; } } return(dtName); }