This constraint cannot be enabled because not all values have corresponding parent values. The solution

Source: Internet
Author: User

In doing the following operation (the realization of the column of the infinite-level tree-shaped list), there have been mistakes.

The original code is as follows

String querysql = "Select Id,title,[level],parentid from Newscata where websitekey= ' + Webkey +" ' and IsNull (issetedite r,0)!=1 or editers like '%, ' + uid + ',% ') Order by ID;//sql try {DataSet myset = Sqlserverpro.executeonesqldataset (con string, querysql);//Get result set foreach (DataRow irow in MySet. Tables[0]. Rows) {if (irow["ParentID"]. ToString () = = "0") {irow["parentid"] = DBNull.Value}} Handles exception//for (int i = 0; i < i++) with no parent value//{//for (int j = 0; J < MySet. Tables[0]. Rows.Count; J + +)//{//bool Biaozhi=false;//String x = MySet. Tables[0]. rows[j]["ParentID"]. ToString (); for (int m = 0; m < MySet. Tables[0]. Rows.Count; m++)//{//if (x = = DBNull.Value.ToString () | | | x = = MySet. Tables[0]. rows[m]["id"]. ToString ())//{//Biaozhi = true;//break;//}//}//if (!biaozhi)//{//MySet. Tables[0]. ROWS[J]. Delete (); MySet. Tables[0]. AcceptChanges (); }//}//} myset. Relations.Add ("Noderela", MySet. Tables[0]. columns["id"], myset. Tables[0]. columns["ParentID"]); foreach (DataRow mrow in MySet. Tables[0]. Rows) {if (Mrow.isnull ("ParentID")) {ListItem item = new ListItem (), item. Text = mrow["title"]. ToString (); Item. Value = mrow["id"]. ToString (); MDOWN.ITEMS.ADD (item); Buildsubtreegrant (Mrow, Mdown); Exception ex) {throw new Exception (ex. message); } }

There are two ways to solve this problem.

One is to change the method, which is the safest and safest method. Because this is the ASP.net self belt.

The Code

MySet. Relations.Add ("Noderela", MySet. Tables[0]. columns["id"], myset. Tables[0]. columns["ParentID"]);

Replaced by

MySet. Relations.Add ("Noderela", MySet. Tables[0]. columns["id"], myset. Tables[0]. columns["ParentID"],false);

Another approach is to write your own code processing, as noted in the code above, for up to 10 levels of the column to deal with.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.