DataTable.Column.Unique

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
 
C

Cor Ligthert[MVP]

Aurora,

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

Cor
 
A

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
 
C

Cor Ligthert[MVP]

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
 
M

Miha Markic

Hi Aurora,

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

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

Top