日期:2014-05-20  浏览次数:20347 次

一个递归的方法,为什么它会覆盖原来循环的值呢?

      有一个地区表(AR_AREA),如:
      AR_PK     AR_NAME     AR_PID
          1             广东           0
          2             广西           0
          3             广州           1
          4             东莞           1
          5             桂林           2
          6             海珠区       3
          7             天河区       3
      有一个单位表(UN_UNIT),如:
      UN_PK         UN_ANME       UN_AREA
          1               AA                   1
          2               BB                   3
          3               CC                   7

我的目的是根据地区ID(UN_AREA),把对应的公司的ID(UN_PK)取出来,如我限制的地区是:用一个变量Name= "1, "来表示,也就是取出广东所有单位的信息,这时就应该把地区是广州(3)、东莞(4)、海珠区   (6)、天河区(7)的单位取出来

                                DataTable   []   DT   =   new   DataTable[2];
string   Name   =   "1, ";
SqlDataAdapter   sda   =   null;
DataSet         ds   =   null;

private   void   cLoad()
{
                                                string   []   att   =   Name.Split( ', ');
for(int   i=0;i <att.Length-1;i++)
{
cLoadUnit(att[i]);
}
}
private   void   cLoadUnit(string   PID)
{
string   SQL     =   "SELECT   *   FROM   UN_UNIT   WHERE   UN_AREA   =   "+   PID;
sda   =   new   SqlDataAdapter(SQL,con);
ds     =   new   DataSet();
ds   =   sda.fill( "AA ");

DT[0]   =   ds.Tables[ "AA "];
for(int   i=0;i <DT[0].Rows.Count;i++)
{
ComID.Text   +=   DT[0].Rows[i][ "UN_PK "].ToString()   +   ", ";
}

string   cSQL   =   "SELECT   *   FROM   AR_AREA   WHERE   AR_SUPERIORAREA   = "+PID;
sda   =   new   SqlDataAdapter(cSQL,con);
                                                ds   =   sda.fill( "BB ")
DT[1]   =   ds.Tables[ "BB "];
for(int   i=0;i <DT[1].Rows.Count;i++)