How to delete duplicate data from DataTable
with particular conditions.
Step by Step Process:
Note - Please delete Step Line and execute direct code.
Step 1: First get the value of table from loop which is coming to Database:
for (ii = dt.Rows.Count - 1; ii >= 0; ii--)
{
c = int.Parse(dt.Rows[0]["cityid"].ToString());
Step 2: This is a counter which is count same value in Datatable.
t = 0;
for (int j = 0; j < dt.Rows.Count; j++)
{
if (c == int.Parse(dt.Rows[j]["cityid"].ToString()))
{
t = t + 1;
jump = int.Parse(dt.Rows[j]["cityid"].ToString());
}
}
Step 3: Display unique data from datatable with count .
output += "<div class=\"pan_tab\">› <a href='SearchwithLocation.aspx?id="
+ dt.Rows[0]["cityid"].ToString() + "&for=" + dt.Rows[0]["PropFor"].ToString() +
"'>" + dt.Rows[0]["cityname"].ToString() + "(" + t + ")" + "</a></div>";
output += "<div class=\"PropFor\">‹ " + dt.Rows[0]["PropFor"].ToString()
+ "</div>";
Step 4: Take the value for match the duplicate data in rows
match = dt.Rows[0]["cityname"].ToString();
Step 5: And match the condition and delete data from row
foreach (DataRow dr in dt.Rows)
{

Join the conversation! Your thoughts help the community grow.