I have been going through various sites and codes, but nothing seems to end my misery. Either they help to find and remove duplicates for a specific column or they remove only from the datatable, not the underlying database itself. I want to delete duplicate rows from table "table1" of my mdb file.
To make my requirements clearer:
- there's no primary key set for any column in the table (and I cant afford to)
- I want to delete all duplicate rows but one! (order has no significance)
- I prefer deleting the duplicates from database more than first checking if such a row exist or not before updating database itself (if that's the last resort, which cant be, then that's welcome)
by duplicate rows I mean rows that are not distinct. for eg, in the following example,only 3rd and 5th row are duplicates. And I want to delete any of them.
Name1 Name2 Name3 tom dick harry tom dick mike ann sara mike sara ann mike ann sara mike
The duplicate rows should be deleted from database with a button click as follows
private void button1_Click(object sender, EventArgs e)
{
deletedupes();
}
private void deletedupes()
{
OleDbConnection con = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\hi.mdb");
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select * from table1", con);
con.Open();
da.Fill(ds, "table1");
// what could be rest of the code??
}
Thanks in advance. Yes I'm a novice..