如何解决自嵌套表“ firstname1”中的循环引用 asp.net
| 这是我在自嵌套表“ firstname1”中得到循环引用的错误。 我要分层数据绑定。员工及其主管在同一表中。 我正在从http://weblogs.asp.net/alessandro/archive/2008/03/01/part-2-building-and-binding-hierarchical-data-from-the-database-to-the-asp获得参考-net-navigation-controls.aspx。 但这在生成Xml时给出了错误。using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings[\"RMSConnection\"].ToString()))
{
string SqlCommand = \"SELECT EmployeeId,FirstName,ReportToId FROM tblEmployee\";
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(
SqlCommand,con);
adapter.Fill(ds);
ds.Tables[0].TableName = \"FirstName1\";
DataRelation dr = new DataRelation(\"pageId_parentId\",ds.Tables[\"FirstName1\"].Columns[\"EmployeeId\"],ds.Tables[\"FirstName1\"].Columns[\"ReportToId\"]);
dr.Nested = true;
ds.Relations.Add(dr);
}
//string s= ds.GetXml();
以上是我的代码。
请提出建议。
解决方法
您的表数据中存在无限循环。
您试图在
EmployeeId
和ReportToId
之间建立链接,但是出了点问题。
您的问题出在所有行上,其中EmployeeId等于ReportToId
范例:
EmployeeId First Name ReportToId
1 Super 1
在所有这些情况下,您需要将ReportToId设置为Null
EmployeeId First Name ReportToId
1 Super Null
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。