Hi!
I wrote these codes. Its delete all replicated row into my table. But the thing is when I press the button to delete the repeated row. Its works! But the repeated action restart to work properly only when I close the program completly.
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Foods\Foods\App_Data\office.mdb;Persist Security Info=False");
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter("select * from movimentoDetalhados", con);
con.Open();
da.Fill(ds, "movimentoDetalhados");
for (int i = 0; i < ds.Tables["movimentoDetalhados"].Rows.Count; i++)
{
DataRow row = ds.Tables["movimentoDetalhados"].Rows[i];
k1++;
for (int j = k1; j < ds.Tables["movimentoDetalhados"].Rows.Count; j++)
{
DataRow row2 = ds.Tables["movimentoDetalhados"].Rows[j];
if (row.ItemArray.GetValue(1).ToString() == row2.ItemArray.GetValue(1).ToString())
{
if (row.ItemArray.GetValue(2).ToString() == row2.ItemArray.GetValue(2).ToString())
{
id1 = int.Parse(row2.ItemArray.GetValue(0).ToString());
deletedupes(id1);
}
}
}
}
con.Close();
}
private void deletedupes(int num)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\LunaFood\LunaFoods\App_Data\office.mdb;Persist Security Info=False");
con.Open();
OleDbCommand c = new OleDbCommand("Delete from movimentoDetalhados where id =?", con);
c.Parameters.AddWithValue("id", num);
c.ExecuteNonQuery();
con.Close();
}