日期:2014-05-18  浏览次数:20433 次

有个递归算法,为什么同一级只能取一条记录?
sub   GetSubTree()
              myCommand1   =   New   OleDb.OleDbCommand( "select   categoryID,categoryName   from   category   where   parentCategoryid= ' "   &   categoryID   &   " '   and   categoryclass= 'category '   and   [language]= ' "   &   radioLanguage.SelectedItem.Value   &   " '   order   by   myorder ",   myConnection)
                myDataReader1   =   myCommand1.ExecuteReader
                Do   While   myDataReader1.Read()
                        dropdownParentID.Items.Add(New   ListItem(strT   &   "├   "   &   Trim(myDataReader1.Item( "categoryName ")).Replace( "  ",   "   "),   myDataReader1.Item( "categoryID ")))
                        getSubTree(myDataReader1.Item( "categoryID "))
                Loop
end   sub

每次循环,先把记录加到一个dropdownlist里,然后对这条记录再递归,取出它所有的子节点,然后再子节点再递归....但要命的是为什么每一层只取第一条记录?即递归调用后没有返回?还是因为用了同一个mydatareader1?


------解决方案--------------------
string str= "Name = "+ " ' "+textBox.text+ " ' ";
DataRow[] foundRows;
foundRows = myDataSet.Tables[ "myDataTable "].Select(str);