Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving duplicate rows from hashtable
    primarykey
    data
    text
    <p>Hi there I have a grid which is being populated with user results on educational courses they have taken part in. For each user they have their own grid showing them each course they have done and their status of each time they have tried the course. For example:</p> <p>CourseTitle | Status<br> Excel, incomplete<br> Body Language, complete<br> Body Language, abandoned<br> Body Language, incomplete<br> Body Language, completed<br> Body Language, completed</p> <p>After removing duplicates the table should look like this: </p> <p>CourseTitle | Status<br> Excel, incomplete<br> Body Language, complete<br> Body Language, abandoned<br> Body Language, incomplete</p> <p>I was trying to do it like this: </p> <p>public static DataTable RemoveDuplicateRows(DataTable dTable, string colName, string colTitle) { Hashtable hTable = new Hashtable(); ArrayList duplicateList = new ArrayList();</p> <pre><code> foreach (DataRow drow in dTable.Rows) { if (hTable.Contains(drow[colName]) &amp;&amp; hTable.Contains(drow[colTitle])) { duplicateList.Add(drow); } else hTable.Add(drow[colName], drow[colTitle]); } foreach (DataRow dRow in duplicateList) dTable.Rows.Remove(dRow); return dTable; } </code></pre> <p>But this way gives me an error: Item has already been added. Key in dictionary: 'incomplete' c#</p> <p>I now know that you cannot have duplicated keys in key,value pairs. Does anyone know a way around this or a different method I could use to solve this problem. Sorry forgot to add that this needs to be added to a datatable.</p> <p>Cheers, James</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload