c# - Removing duplicates from an array populated by a reader -
i have database column has several names separated commas in each row. i'm trying populate data-table containing names without duplicates.
currently list populates duplicate names still appear.
my code is:
while (reader.read()) { string[] array = reader[0].tostring().split(','); string[] unique = array.distinct().toarray(); foreach (string s in unique) dt.rows.add(s); }
any help appreciated, thanks.
try this
list<string> distinctvalues = new list<string>(); while (reader.read()) { string[] unique = reader[0].tostring().split(',').distinct().toarray(); foreach (string s in unique) if (!distinctvalues.contains(s)) distinctvalues.add(s); } foreach (string s in distinctvalues) dt.rows.add(s)
c# sql arrays sqldatareader
No comments:
Post a Comment