PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

DataTable.Column.Unique

 
 
Aurora
Guest
Posts: n/a
 
      9th May 2009
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


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      10th May 2009
Aurora,

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

Cor

"Aurora" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>


 
Reply With Quote
 
Aurora
Guest
Posts: n/a
 
      10th May 2009
Thre is question. How do I solve the problem?

Aurora


"Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
news:ec6$(E-Mail Removed)...
> Aurora,
>
> Thanks for the information, but most of us know this already.
>
> Cor
>
> "Aurora" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>>

>



 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      10th May 2009
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thre is question. How do I solve the problem?
>
> Aurora
>
>
> "Cor Ligthert[MVP]" <(E-Mail Removed)> wrote in message
> news:ec6$(E-Mail Removed)...
>> Aurora,
>>
>> Thanks for the information, but most of us know this already.
>>
>> Cor
>>
>> "Aurora" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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
>>>

>>

>
>


 
Reply With Quote
 
Miha Markic
Guest
Posts: n/a
 
      13th May 2009
Hi Aurora,

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

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: blog.rthand.com

"Aurora" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unique string column on DataTable ? =?Utf-8?B?UmljaGFyZCBDaGFuZGxlcg==?= Microsoft ADO .NET 6 25th May 2007 05:24 AM
Find Unique Values in a DataTable Column =?Utf-8?B?Q2hyaXM=?= Microsoft ADO .NET 3 2nd Jul 2006 06:17 AM
Unique values from column in DataTable (source = xml) Fred Microsoft C# .NET 1 1st May 2006 08:12 PM
How do you create a Datatable with a non-unique index on a column? Kevin Microsoft ADO .NET 0 11th Jan 2006 05:05 PM
Create a Datatable from a SQL datatable column shema? jg Microsoft ASP .NET 1 17th Aug 2004 10:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 PM.