Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8573701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:18:40+00:00 2026-06-11T19:18:40+00:00

<WebMethod(Description:=JSON Hierarchy Object)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ Public Function xmlData() As Object Using _ds As

  • 0
<WebMethod(Description:="JSON Hierarchy Object")> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function xmlData() As Object

        Using _ds As DataSet = db.ExecuteDataSet(CommandType.Text, "Select NodeID, NodeName,ParentID from Nodes WHERE ParentID=1")
            _ds.DataSetName = "Menus"
            _ds.Tables(0).TableName = "Menu"
            Dim relation As New DataRelation("ParentChild", _ds.Tables("Menu").Columns("NodeID"), _ds.Tables("Menu").Columns("ParentID"), True)
            relation.Nested = True
            _ds.Relations.Add(relation)
            Dim StrDc As String() = New String(_ds.Tables(0).Columns.Count - 1) {}
            Dim HeadStr As String = String.Empty
            For i As Integer = 0 To _ds.Tables(0).Columns.Count - 1
                StrDc(i) = _ds.Tables(0).Columns(i).Caption
                HeadStr += """" + StrDc(i) + """ : """ + StrDc(i) + i.ToString() + "¾" + ""","
            Next
            HeadStr = HeadStr.Substring(0, HeadStr.Length - 1)
            Dim Sb As New StringBuilder()
            Sb.Append("{""" + _ds.Tables(0).TableName + """ : [")
            For i As Integer = 0 To _ds.Tables(0).Rows.Count - 1
                Dim TempStr As String = HeadStr
                Sb.Append("{")
                For j As Integer = 0 To _ds.Tables(0).Columns.Count - 1
                    TempStr = TempStr.Replace(_ds.Tables(0).Columns(j).ToString + j.ToString() + "¾", _ds.Tables(0).Rows(i)(j).ToString())
                Next
                Sb.Append(TempStr + "},")
            Next
            Sb = New StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1))
            Sb.Append("]}")
            Return Sb.ToString
        End Using

    End Function

I am using the above function to return a JSON String but when i use ParentID=1 in this sql Query Select NodeID, NodeName,ParentID from Nodes WHERE ParentID=1 i get the following error

System.ArgumentException: This constraint cannot be enabled as not all values have corresponding parent values.
   at System.Data.ConstraintCollection.AddForeignKeyConstraint(ForeignKeyConstraint constraint)
   at System.Data.ConstraintCollection.Add(Constraint constraint, Boolean addUniqueWhenAddingForeign)
   at System.Data.DataRelationCollection.DataSetRelationCollection.AddCore(DataRelation relation)
   at System.Data.DataRelationCollection.Add(DataRelation relation)
   at Haggler.xmlData() in D:\2008VS\Haggler\EntLib5\App_Code\Haggler.vb:line 114

Table Structure:

enter image description here

It works fine when i remove the Where Clause from the Sql Query..any help immensely appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:18:41+00:00Added an answer on June 11, 2026 at 7:18 pm

    You can replace with this code (Replace True with False)

    Dim relation As New DataRelation("ParentChild", _ds.Tables("Menu").Columns("NodeID"), _ds.Tables("Menu").Columns("ParentID"), False)
    

    Link : http://msdn.microsoft.com/fr-fr/library/9ae5a582%28v=vs.80%29.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code snippet for a JSON request. <WebMethod(Description:=Gets the Categories)>
Code Behind: [WebMethod] public static string emp() { return BlaBla; } Aspx Page: $(document).ready(function()
[WebMethod(Description = Return all activities by Task.)] public IList<ActivityDto> GetActivitiesByTaskID(int taskID) { IList<Activity> activities
I have following webservice: [webmethod] public string MakeReservation(?? PassengersInfo)//what data type use for PassengerInfo
Im trying to run a sipmle ASP.NET 2 Webmethod with JSON this is my
Hi, I am trying to save data using web services, jquery and json. From
I had a webmethod working which returned a byte array to the caller: public
I'm trying to send a complex object to my WebMethod in a aspx page
I have a WebService defined as this: <WebMethod(Description:=Retrieve a list of account profiles.)> _
I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.