1.将过滤的结果导入到临时表
select distinct * into 临时表 from 原表名
2.删除原表
delete table 原表名
3.将临时表的数据转移到原始表里
select distinct * into 原表名 from 临时表
4.删除临时表
drop table Tmp
/// <summary> /// 删除重复数据,只保留一条数据 /// </summary> /// <param name="mdbPath">mdb路径</param> public void DistinctTable(string mdbPath) { try { string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + mdbPath; DataTable dtTableName = OleDbHelper.GetExcelTables(connectionString); AccessHelper acchelp = new AccessHelper(connectionString); for (int i = 0; i < dtTableName.Rows.Count; i++) { string name = dtTableName.Rows[i]["TABLE_NAME"].ToString(); //1.将过滤的重复数据 存放在临时表里 acchelp.ExecuteSQL(@"select distinct * into tmpTable from " + name); //2.删除原表 acchelp.ExecuteSQL(@"drop table " + name); //3.将临时表的数据转移到原始表里 acchelp.ExecuteSQL(string.Format(@"select * into {0} from tmpTable", name)); //4.删除临时表 acchelp.ExecuteSQL(@"drop table tmpTable"); } dtTableName.Clear(); dtTableName = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }