I am building a custom search control in VB.NET and came across a problem getting distinct records into my datagridview.
I want to bring exact matches back first so I run 2 of the same query on the same table with a slight difference:
select ... like "code%"
select ... like "%code%"
I have a datatable that I need to get distinct records from; I am append records from a sql query to the end of the datatable so I cannot use a union in sql to return the dataset (I want to preserve the order which the rows are added)
I have been using this which is working fine for 2 fields:
dt2 = dt.DefaultView.ToTable(True, "Code", "Name")
But when I have 3 (or more) fields I get duplicates ONLY for the row I am querying:
dt2 = dt.DefaultView.ToTable(True, "Code", "Name", "Initial")
select ... like "initial%"
select ... like "%intial%"
I am clearing the datagridview.source before rebuilding this.
Is there a way to get the distinct rows this way or should I just build something myself to remove the duplicates from the second datatable before appending them to the new table?
I believe there is a bug or limitation in datatable.DefaultView.ToTable since I narrowed it down to datatables with more than two columns.