distinct value in dataview

  • Thread starter Thread starter rodchar
  • Start date Start date
R

rodchar

hey all,
i have a dataview with a single column in it which contains duplicates. What
is the best way to eliminate the duplicates rows so i can turn this column
into the primary key?

thanks,
rodchar
 
rodchar,

You will have to cycle through the rows, keeping track of the column
value for each row (a Dictionary<X, DataRow> would help, where X is the type
of the value in the column you are looking at) and then removing the row if
you find a duplicate.
 
Also, are you trying to change this column into a primary key in the
underlying data source, or you just want to do it in the data table that the
data view is on? If the answer is the former, then you have to actually
remove those records from the database before you change the structure of
the table.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas Paldino said:
rodchar,

You will have to cycle through the rows, keeping track of the column
value for each row (a Dictionary<X, DataRow> would help, where X is the
type of the value in the column you are looking at) and then removing the
row if you find a duplicate.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

rodchar said:
hey all,
i have a dataview with a single column in it which contains duplicates.
What
is the best way to eliminate the duplicates rows so i can turn this
column
into the primary key?

thanks,
rodchar
 
I just wanted to changed datatable and not the source. Also, I found
DataView.ToTable() function where you can specify distinct values, i thought
that was pretty neat.

thanks everyone for the help,
rod.

Nicholas Paldino said:
Also, are you trying to change this column into a primary key in the
underlying data source, or you just want to do it in the data table that the
data view is on? If the answer is the former, then you have to actually
remove those records from the database before you change the structure of
the table.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas Paldino said:
rodchar,

You will have to cycle through the rows, keeping track of the column
value for each row (a Dictionary<X, DataRow> would help, where X is the
type of the value in the column you are looking at) and then removing the
row if you find a duplicate.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

rodchar said:
hey all,
i have a dataview with a single column in it which contains duplicates.
What
is the best way to eliminate the duplicates rows so i can turn this
column
into the primary key?

thanks,
rodchar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top