This is a migrated thread and some comments may be shown as answers.

Error when using Stored Proc.

3 Answers 95 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
michel
Top achievements
Rank 1
michel asked on 19 Dec 2011, 12:44 PM
When I bind the control to the datasource I got the following Error:

This constraint cannot be enabled as not all values have corresponding parent values.

Here is My Proc. :

Create

 

proc [sel_user]

 

@username

int

 

as

select

 

* from dbo.MinaTableOne

 

where

 

id= @username

But When I remove the Where Cluse It works Fine
so When I use this Proc. :

 

Create proc [sel_user]

 

@username

int

 

as

select

 

* from dbo.MinaTableOne

 

 

Also here is my code:

 

 

 

Dim dt As DataTable

 

 

 

 

dt = Nothing

 

 

 

 

dt = New DataTable

 

 

 

 

dt = ins.selectPOcombo(1013)

 

RadOrgChart1.DataTextField = dt.Columns(1).ToString

RadOrgChart1.DataFieldID = dt.Columns(0).ToString

RadOrgChart1.DataFieldParentID = dt.Columns(5).ToString

RadOrgChart1.DataSource = dt

RadOrgChart1.DataBind()

Note "ins" is my ADO Class

 

Any Ideas Why
Thanks

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 19 Dec 2011, 06:21 PM
Hello Michel,

The problem comes from the fact that after the where clause is executed, the child nodes of the removed parent nodes are still in the collection, but have their parentID pointing to a node that doesn't exist.
To bind the OrgChart correctly, in your stored procedure you have to recursively filter out all child nodes of the removed nodes, or set their parentID to NULL

All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Tzahi
Top achievements
Rank 1
answered on 14 Jul 2012, 08:47 AM
Hi,

Can you elaborate on the solution?

Let's say I have a table with the following fields: ID, FullName, ReportsToID
I still get the same exception.

obviously, I have some Where clause in my qurey.
0
Bozhidar
Telerik team
answered on 18 Jul 2012, 07:25 AM
Hello Tzahi,

Let's say you have the following records in your database:

ID FullName ReportsToID

1 Name1 NULL
2 Name2 1
3 Name3 1
4 Name4 2

As you can see, all records have their ReportsToID field pointing to a valid record, and the first one has a value NULL, which makes it the root. 

Now let's say your stored procedure returns a result like this:

ID FullName ReportsToID

1 Name1 NULL
3 Name3 1
4 Name4

Now you have the record with ID=4 pointing to a record with ID=2, which is not present in the result, and this is what is causing the error.

So the solution to this is to construct your stored procedure in such a way, so that it returns only the records that have a valid parent ( in this case, records 1 and 3 )
 
Greetings,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
OrgChart
Asked by
michel
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Tzahi
Top achievements
Rank 1
Share this question
or