DataTable.Column.Unique

  • Thread starter Thread starter Aurora
  • Start date Start date
A

Aurora

I have a DataTable with two columns : GroupID which is primary key and
second GroupName which I would like to hold groups name in a unique way, so
that it may not be two groups with same name.
Is there a way to set this feature using DataTable class?
I have tried . dt.Column["GroupName"].Unique = true;


and I get as below

System.Data.InvalidConstraintException was unhandled
Message="Column 'GroupName' contains non-unique values."
Source="System.Data"

Thanks,
Aurora
 
Thre is question. How do I solve the problem?

Aurora


Cor Ligthert said:
Aurora,

Thanks for the information, but most of us know this already.

Cor

Aurora said:
I have a DataTable with two columns : GroupID which is primary key and
second GroupName which I would like to hold groups name in a unique way,
so that it may not be two groups with same name.
Is there a way to set this feature using DataTable class?
I have tried . dt.Column["GroupName"].Unique = true;


and I get as below

System.Data.InvalidConstraintException was unhandled
Message="Column 'GroupName' contains non-unique values."
Source="System.Data"

Thanks,
Aurora
 
That depends what you expect.

There is an error given, so it means you try to add a columname that already
expect.
It is up to you what you want to do with it.

Cor

Aurora said:
Thre is question. How do I solve the problem?

Aurora


Cor Ligthert said:
Aurora,

Thanks for the information, but most of us know this already.

Cor

Aurora said:
I have a DataTable with two columns : GroupID which is primary key and
second GroupName which I would like to hold groups name in a unique way,
so that it may not be two groups with same name.
Is there a way to set this feature using DataTable class?
I have tried . dt.Column["GroupName"].Unique = true;


and I get as below

System.Data.InvalidConstraintException was unhandled
Message="Column 'GroupName' contains non-unique values."
Source="System.Data"

Thanks,
Aurora
 
Hi Aurora,

Looks like your table is already populated with conflicting values. Set the
Unique=true before populating the data.
 
Back
Top