问题描述
usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){TreeNoderoot=getNodes();this.TreeView1.Nodes.Add(root);try{bind(root);}catch(Exceptionex){throwex;}}voidbind(TreeNoderoot){ArrayListal=getNodeParent(root);if(al.Count==0){}else{foreach(TreeNodetrinal){bind(tr);root.ChildNodes.Add(tr);}}}protectedvoidButton1_Click(objectsender,EventArgse){}publicstaticvoidadd(SqlConnectionconn,SqlTransactiontran){}publicstaticTreeNodegetNodes(){TreeNodetr=newTreeNode();stringstrsql="DataSource=192.168.4.90;InitialCatalog=MMiEMS_Test;UserID=sa;Password=maoming";SqlConnectionconn=newSqlConnection(strsql);conn.Open();stringsql="selectidfromt_cardcontent3";SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReadersdr=cmd.ExecuteReader();ArrayListalid=newArrayList();while(sdr.Read()){alid.Add(sdr.GetInt32(0));}sdr.Close();foreach(intiinalid){stringid="";if(i<10){id="00"+i;}elseif(i<100&&i>10){id="0"+i;}stringsql1="selectid,field1fromt_cardcontent3wherefield2639="+"'B"+id+"'";cmd=newSqlCommand(sql1,conn);sdr=cmd.ExecuteReader();while(sdr.Read()){tr.Text=sdr.GetString(1);tr.Value=sdr.GetInt32(0).ToString();}sdr.Close();}conn.Close();returntr;}publicstaticArrayListgetNodeParent(TreeNodet){ArrayListal=newArrayList();stringstrsql="DataSource=192.168.4.90;InitialCatalog=MMiEMS_Test;UserID=sa;Password=maoming";SqlConnectionconn=newSqlConnection(strsql);conn.Open();inti=int.Parse(t.Value);stringid="";if(i<10){id="00"+i;}elseif(i<100&&i>10){id="0"+i;}stringsql="selectid,field1fromt_cardcontent3wherefield2639='B"+id+"'";SqlCommandcmd=newSqlCommand(sql,conn);SqlDataReadersdr=cmd.ExecuteReader();while(sdr.Read()){TreeNodetr=newTreeNode();tr.Text=sdr.GetString(1);tr.Value=sdr.GetInt32(0).ToString();al.Add(tr);}conn.Close();returnal;}}
解决方案
解决方案二:
恕我眼拙。你哪里用递归了?
解决方案三:
foreach(intiinalid){stringid="";if(i<10){id="00"+i;}elseif(i<100&&i>10){id="0"+i;}stringsql1="selectid,field1fromt_cardcontent3wherefield2639="+"'B"+id+"'";//问题可能在这句代码上stringsql1="selectid,field1fromt_cardcontent3wherefield2639="+"'B"+id+"'";//是用来做什么的