Solved

Error:  ArgumentException These columns don't currently have unique values.

Posted on 2015-01-15
9
536 Views
Last Modified: 2015-01-16
From within my .asp.cs I do a select ( select * from vw1, then select * from vw2) from two Oracle views that are populated with DISTINCT values from two tables, then create a datastore (array) and want to insert two columns, column1 and column2 into that array.  Because I am selecting DISTINCT values, I am confused about why I would get a uniqueconstraint error.  The database is Oracle, and the code is C#.  More details below from the error log.  


at System.Data.ConstraintCollection.AddUniqueConstraint(UniqueConstraint constraint) at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign) at System.Data.DataTable.set_PrimaryKey(DataColumn[] value) at MasterPage.GetDataSetForTree() in e:\Websitefolder\MasterPage.master.cs:line 153 at MasterPage.PopulateTree() in e:\Websitefolder\MasterPage.master.cs:line 44 at MasterPage.Page_Load(Object sender, EventArgs e) in e:\Websitefolder\MasterPage.master.cs:line 27 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Control.LoadRecursive() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
0
Comment
Question by:newtoperlpgm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40552289
Can you post the code causing the error?

Are you creating a single array from both queries?  Each query is distinct but putting the two of them together may not be.
0
 

Author Comment

by:newtoperlpgm
ID: 40552299
Here is the code that does the select:

using (Myconnection)
        {

            // Define the Level 1query.
            string queryString =
                "SELECT DISTINCT LEVEL1 FROM Locs Order By Level1 ";

            // Create the Level 1 DbCommand.
            DbCommand command = factory.CreateCommand();
            command.CommandText = queryString;
            command.Connection = Myconnection;
            // Create the DataAdapter
            DbDataAdapter adArea = factory.CreateDataAdapter();
            adArea.SelectCommand = command;

            DataSet ds = new DataSet();
            adArea.Fill(ds, "Areas");
            // Create primary key on Areas
            DataTable tblAreas = ds.Tables["Areas"];
            tblAreas.PrimaryKey = new DataColumn[] { tblAreas.Columns["Level1"] };

            // Define the Level 2 query.
            string queryString2 =
                "SELECT DISTINCT LEVEL1, LEVEL2 FROM Bldgs ";

            // Create the Level 1 DbCommand.
            DbCommand command2 = factory.CreateCommand();
            command2.CommandText = queryString2;
            command2.Connection = Myconnection;

            // Create the DataAdapter
            DbDataAdapter adBuilding = factory.CreateDataAdapter();
            adBuilding.SelectCommand = command2;

            adBuilding.Fill(ds, "Buildings");
            // Create a new DataTable and set two DataColumn objects as primary keys.
            DataTable tblBuildings = ds.Tables["Buildings"];
            // Set the PrimaryKeys property to the array.
            //tblBuildings.PrimaryKey = new DataColumn[] { tblBuildings.Columns["Level1"], tblBuildings.Columns["Level2"] };

            //adBuilding.Fill(ds, "Buildings");
            // Create a new DataTable and set two DataColumn objects as primary keys.
            //DataTable tblBuildings = ds.Tables["Buildings"];
            // Set the PrimaryKeys property to the array.
            tblBuildings.PrimaryKey = new DataColumn[] { tblBuildings.Columns["Level1"], tblBuildings.Columns["Level2"] };

            //adLoc.Fill(ds, "Locs");
            ds.Relations.Add("Children",
            ds.Tables["Areas"].Columns["Level1"],
            ds.Tables["Buildings"].Columns["Level1"]);

            return ds;
        }
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40552495
First:  It appears you aren't using ODP.Net, you should be.

That said, what are the data types for the primary key columns?

If varchar2 it might be a case issue.  The default is 'false':
http://msdn.microsoft.com/en-us/library/system.data.dataset.casesensitive%28v=vs.110%29.aspx
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:newtoperlpgm
ID: 40554177
It's a vendor product, so I will have to talk to them about using ODP .NET, thank you.  So if I understand this correctly, the following data will cause the error?

Daily Control Point
Daily Control point

Thanks very much.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40554246
>>So if I understand this correctly, the following data will cause the error?

That is how I understand it from reading the docs.  I didn't set up my own test case to confirm it.
0
 

Author Comment

by:newtoperlpgm
ID: 40554473
That is my problem then.  I changed the data to and it fixed my problem.  Thanks very much.  Additionally, in our Oracle database, if we have the ignore case attribute set to true, that could be my problem, is that correct?  Would setting it to false fix the issue, I will test in my development environment.

Daily Control Point
Daily Controlpoint
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40554542
>> in our Oracle database, if we have the ignore case attribute set to true

I'm not aware of a database attribute/parameter that does this.

If you are talking about the .Net DataSet.CaseSensitive Property, you would need true since the default is false.

Right now that is just a guess as to the problem but since you 'cleaned' the data and the code runs, it is looking good that it was a case issue.

I don't know what this was supposed to tell me.
Daily Control Point
Daily Controlpoint
0
 

Author Comment

by:newtoperlpgm
ID: 40554764
Daily Control Point
Daily Controlpoint

this was the data that was causing the problem.  I changed the second value to Daily Controlpoint from Daily Control point so that the data wouldn't be the same with the exception of the p in point.  
Thanks for your help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question