显示记录,其实再简单不过了,一条sql语句即可
Select * From T_Class order By F_RootID,F_Orders
下面给出一个ASPX(C#版)的示例
Database.ConnectionString = "Data Source=127.0.0.1;Initial Catalog=cntvs;Persist Security Info=True;User ID=sa;Password=3power";
string _strSql = "Select * from T_Class order By F_rootId,F_Orders";
SqlConnection conn = Database.GetConn();
//插入几个演示用的节点
Database.ExecuteNonQuery(conn, CommandType.Text, "truncate table T_Class");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx 'c12fe245-75ec-4b28-82e1-99e501672f41','product','00000000-0000-0000-0000-000000000000','A',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '0c630080-51b0-4b92-bd6c-99e50167d8a5','product','c12fe245-75ec-4b28-82e1-99e501672f41','A1',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '9eeda546-927e-4b2a-a4e8-99e501681676','product','0c630080-51b0-4b92-bd6c-99e50167d8a5','A11',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx 'bc36649c-736a-467f-b2f1-99e501687083','product','0c630080-51b0-4b92-bd6c-99e50167d8a5','A12',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '2b975d64-27c7-4759-b475-99e50168d622','product','c12fe245-75ec-4b28-82e1-99e501672f41','A2',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx 'b2703d81-60c8-4e08-8ed4-99e50169376b','product','2b975d64-27c7-4759-b475-99e50168d622','A21',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '91ca8257-317e-4a6b-ab33-99e50169540a','product','2b975d64-27c7-4759-b475-99e50168d622','A22',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '4ce0b1de-68ab-4e2b-bb85-99e5016961b7','product','2b975d64-27c7-4759-b475-99e50168d622','A23',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx 'cc05c6e0-fde8-4f1c-aac6-99e50169f995','product','4ce0b1de-68ab-4e2b-bb85-99e5016961b7','A231',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx '31c710bd-d2ff-4ffb-a8e9-99e50169eee4','product','4ce0b1de-68ab-4e2b-bb85-99e5016961b7','A232',''");
Database.ExecuteNonQuery(conn, CommandType.Text, "exec up_Class_InsertEx 'c11d5fc2-cb6b-488c-b97c-99e5016a4c9a','product','c12fe245-75ec-4b28-82e1-99e501672f41','A3',''");
//读出节点
SqlDataReader sdr = Database.ExecuteReader(conn, CommandType.Text, _strSql);
while (sdr.Read())
{
string t = "";
for (int i = 0; i < Convert.ToInt16(sdr["F_Depth"].ToString()); i++)
{
t += " |- ";
}
Response.Write(t + sdr["F_ClassName"].ToString() + "<br/>");
}
sdr.Close();
Database.Dispose(conn);
最终页面上的显示结果如下:
A
|- A1
|- |- A11
|- |- A12
|- A2
|- |- A21
|- |- A22
|- |- A23
|- |- |- A231
|- |- |- A232
|- A3