Error when using Stored Proc.

4 posts, 0 answers
  1. michel
    michel avatar
    6 posts
    Member since:
    Aug 2011

    Posted 19 Dec 2011 Link to this post

    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

  2. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 19 Dec 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tzahi
    Tzahi avatar
    2 posts
    Member since:
    Aug 2011

    Posted 14 Jul 2012 Link to this post

    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.
  5. Bozhidar
    Admin
    Bozhidar avatar
    1101 posts

    Posted 18 Jul 2012 Link to this post

    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.
Back to Top