2011-04-14 34 views
2

這是我得到「循環引用自嵌套表'firstname1'」中的錯誤。自嵌套表'firstname1'中的循環引用。 asp.net

我想要分層數據綁定。員工和他們的主管在同一張桌子上。

我參照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();  

上面是我的代碼。 請建議。

enter image description here

+0

您必須提供更多數據,因爲這些數據基本上都是從Internet示例中複製而來。堅實的問題處理依賴於更廣泛的數據基礎。 – AGuyCalledGerald 2011-04-14 14:03:22

回答

1

你有你的表的數據無限循環。 您正在嘗試建立EmployeeIdReportToId之間的鏈接,但有些地方出錯。

您的問題與您的所有行,所述僱員等於ReportToId

例:

EmployeeId First Name ReportToId 
1   Super  1 

所有這些情況下,您需要設置ReportToId爲Null

EmployeeId First Name ReportToId 
1   Super  Null 
+0

感謝您的回覆。我附上了數據屏幕截圖。員工及其主管數據位於同一個表中。報告代表主管。 – 2011-04-15 05:27:21

+0

@莫漢看我編輯 – DavRob60 2011-04-15 11:04:50

+1

@ DavRib60:非常感謝。 – 2011-04-15 11:14:03