Home All Groups Group Topic Archive Search About

Finding if a column is unique in a dataset

Author
9 Mar 2006 10:44 PM
spdude
I have a dataset that has megs of data. I want to know if there is a
way to find out if data in a particular column is unique or not. Does
the dataset or a datatable have a built in function that i can use?

Thanks

Author
10 Mar 2006 6:28 AM
Steven Nagy
DataColumn.Unique

But it is only going to be set to Unique if you have set it that way,
or if it was auto-generated that way in your dataset schema.
How are you filling your dataset, and is it strongly typed?
Are all your drivers up to date? click for free checkup

Author
10 Mar 2006 4:03 PM
spdude
Thanks. No, the dataset is not strongly typed and I am filling the
dataset from a datasource and I am not sure if this datasource has any
unique constraints on the data.
Author
10 Mar 2006 4:16 PM
spdude
Ok, I am doing this:

bool isUnique = data.Tables["Item"].Columns["Number"].Unique;

Now, if isUnique is false, is there a way to find out the value of the
item that's duplicate?
Author
12 Mar 2006 10:30 PM
Steven Nagy
ok. Yeah you would need to loop through and check for duplicates.
A loop inside a loop would be the quickest and easiest way, but
depending how many rows you have, not that effecient.

Bookmark and Share