递归 出错
public static string GetGroupTopParent3(string user_Dept)
{
Forms_AjaxFunctions f = new Forms_AjaxFunctions();
string sql = "select Group_ID,Group_ParentID from SYS_BPS_GROUPS where Group_Name = '" + user_Dept + "'";
DataTable dt = DbHelperSQL.Query(sql).Tables[0];
string aa = f.GetGroupCode(Convert.ToString(dt.Rows[0]["Group_ParentID"]).Trim(), Convert.ToString(dt.Rows[0]["Group_ID"]).Trim());
return aa;
}
public string GetGroupCode(string parentID, string groupCode)
{
DataTable dt = new DataTable();
DataTable dtReturn = new DataTable();
if (!string.IsNullOrEmpty(parentID))
{
if (Convert.ToInt32(parentID)!=0)
{
string sqlP = "select Group_ID,Group_ParentID from SYS_BPS_GROUPS where Group_ID = " + parentID + "";
dt = DbHelperSQL.Query(sqlP).Tables[0];
GetGroupCode(Convert.ToString(dt.Rows[0]["Group_ParentID"]).Trim(), Convert.ToString(dt.Rows[0]["Group_ID"]).Trim());
}
}
return groupCode;
}
为什么 parentID=0时 return groupCode 完了 还会继续走GetGroupCode(xx,xx)? 求解
------解决方案--------------------GetGroupTopParent3会一直递归下去,因为没有条件可以让递归退出,知道溢出报错
加上退出条件
GetGroupTopParent3()
{
if(xxxxx)
return;
}
------解决方案--------------------