newtoperlpgm
asked on
Error: ArgumentException These columns don't currently have unique values.
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.ConstraintColl ection.Add UniqueCons traint(Uni queConstra int constraint) at System.Data.ConstraintColl ection.Add (Constrain t constraint, Boolean addUniqueWhenAddingForeign ) at System.Data.DataTable.set_ PrimaryKey (DataColum n[] value) at MasterPage.GetDataSetForTr ee() in e:\Websitefolder\MasterPag e.master.c s:line 153 at MasterPage.PopulateTree() in e:\Websitefolder\MasterPag e.master.c s:line 44 at MasterPage.Page_Load(Objec t sender, EventArgs e) in e:\Websitefolder\MasterPag e.master.c s:line 27 at System.Web.Util.CalliHelpe r.EventArg FunctionCa ller(IntPt r fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEvent HandlerDel egateProxy .Callback( Object sender, EventArgs e) at System.Web.UI.Control.OnLo ad(EventAr gs e) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Control.Load Recursive( ) at System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt)
at System.Data.ConstraintColl
ASKER
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["Leve l1"], tblBuildings.Columns["Leve l2"] };
//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["Leve l1"], tblBuildings.Columns["Leve l2"] };
//adLoc.Fill(ds, "Locs");
ds.Relations.Add("Children ",
ds.Tables["Areas"].Columns ["Level1"] ,
ds.Tables["Buildings"].Col umns["Leve l1"]);
return ds;
}
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["Leve
//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["Leve
//adLoc.Fill(ds, "Locs");
ds.Relations.Add("Children
ds.Tables["Areas"].Columns
ds.Tables["Buildings"].Col
return ds;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Daily Control Point
Daily Control point
Thanks very much.
>>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.
That is how I understand it from reading the docs. I didn't set up my own test case to confirm it.
ASKER
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
Daily Control Point
Daily Controlpoint
>> 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.
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
ASKER
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.
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.
Are you creating a single array from both queries? Each query is distinct but putting the two of them together may not be.