Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2006, 02:39 PM
Registered User
 
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataSet Column with Unique Constrain Problem

Hello.

I created a DataSet with a few tables. One of them contains a column that is not required but it is unique.

xpto.Tables["a"].Columns["x"].AllowDBNull = true;
xpto.Tables["a"].Columns["x"].Unique = true;

Since this column is not required, empty values can be added. I use DBNull.Value as empty values.

In this case, when I add to rows with empty x column, I get the following error:

Column x is constrained to be unique. Value '' is already present.

The DataBase I use is Access. There I have no problems because I can say that I do not accept Duplicates, and when I add two rows with an empty x I get no errors.

Any ideas?

Thanks for your help.
Fred
 
Old July 16th, 2006, 09:25 PM
op op is offline
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are there two or more empty x in table xpto?
 
Old July 17th, 2006, 05:59 PM
Registered User
 
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. To empty values (DBNull.Value).

Thanks.
Fred
 
Old July 18th, 2006, 08:42 PM
op op is offline
Registered User
 
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by niceFEPF
 Yes. To empty values (DBNull.Value).

Thanks.
Fred
The Column x must be unique but you used two empty values.Right?

 
Old September 26th, 2006, 04:30 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you check to make sure that the dataset configuration matches the database config? Sometimes I've found that the ds will need updating for various reasons. Make sure the ds also has DBNull set to true.

 
Old July 31st, 2009, 07:04 PM
Registered User
 
Join Date: Jul 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't have unique column that is also blank, it makes no sense. More than one blank entry is not unique so that explains the error. It's Microsofts fault for allowing it really.

Why would you want a unique column but leave it blank anyway? Seems pointless.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with dataset autoincrement column Jayaram ADO.NET 0 December 4th, 2006 03:13 PM
Vertically Constrain GridView wirerider ASP.NET 2.0 Basics 3 February 6th, 2006 06:53 PM
Unique values from a dataset gbuller Pro VB.NET 2002/2003 3 September 27th, 2004 12:17 PM
dataset column not in data base table gbuller ADO.NET 4 August 18th, 2004 10:18 PM
duplicate nulls in a column with unique constraint defiant SQL Server 2000 3 October 22nd, 2003 01:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.