public static void DelCheckReady(string NodeText)
{
DataSet dsDelmnu;
int cnttemp1;
//得到该菜单在数据库中的ID
strsql="select * from tbmnuManage where Name='"+NodeText+"'";
dsDelmnu=SqlExcute("tbmnuManage","SqlExcute","Rs",false);(查询该菜单名的id,执行存储过程)
//传值给cntTemp来映射DelMnu执行删除
cntTemp=Convert.ToInt32(dsDelmnu.Tables["tbmnuManage"].Rows[0][0]);
dsDelmnu=SqlExcute("tbmnuManage","DelMnu","Rs",false);(执行存储过程delmnu)
MessageBox.Show(NodeText +"下面有"+dsDelmnu.Tables["tbmnuManage"].Rows.Count+"个菜单");
if(dsDelmnu.Tables["tbmnuManage"].Rows.Count!=0)//如果有子菜单将继续删
{
cnttemp1=dsDelmnu.Tables["tbmnuManage"].Rows.Count;
for(int i=0;i<cnttemp1;i++)
{
strTemp=dsDelmnu.Tables["tbmnuManage"].Rows[i][3].ToString();程序走到这里,就死了,由于循环变量cnttemp1不会变,一只停留在最后一次循环的计数值,
DelCheckReady(strTemp);这里为递归调用本身!请高手解决阿,以前做c的时候可以调本身的,那么c#应该也可以吧!如果不能,那么请高手如何实现递归!我要调本身,有其他办法解决么?
}
}
if(dsDelmnu!=null)
{
dsDelmnu.Dispose();
}
}
以上程序是为了删除菜单而作的,菜单结构自己设计的,我用存储过程删的!
{
DataSet dsDelmnu;
int cnttemp1;
//得到该菜单在数据库中的ID
strsql="select * from tbmnuManage where Name='"+NodeText+"'";
dsDelmnu=SqlExcute("tbmnuManage","SqlExcute","Rs",false);(查询该菜单名的id,执行存储过程)
//传值给cntTemp来映射DelMnu执行删除
cntTemp=Convert.ToInt32(dsDelmnu.Tables["tbmnuManage"].Rows[0][0]);
dsDelmnu=SqlExcute("tbmnuManage","DelMnu","Rs",false);(执行存储过程delmnu)
MessageBox.Show(NodeText +"下面有"+dsDelmnu.Tables["tbmnuManage"].Rows.Count+"个菜单");
if(dsDelmnu.Tables["tbmnuManage"].Rows.Count!=0)//如果有子菜单将继续删
{
cnttemp1=dsDelmnu.Tables["tbmnuManage"].Rows.Count;
for(int i=0;i<cnttemp1;i++)
{
strTemp=dsDelmnu.Tables["tbmnuManage"].Rows[i][3].ToString();程序走到这里,就死了,由于循环变量cnttemp1不会变,一只停留在最后一次循环的计数值,
DelCheckReady(strTemp);这里为递归调用本身!请高手解决阿,以前做c的时候可以调本身的,那么c#应该也可以吧!如果不能,那么请高手如何实现递归!我要调本身,有其他办法解决么?
}
}
if(dsDelmnu!=null)
{
dsDelmnu.Dispose();
}
}
以上程序是为了删除菜单而作的,菜单结构自己设计的,我用存储过程删的!
strTemp=dsDelmnu.Tables这句话有问题啊。。
应该是 string strTemp = dsDelmnu.Tables[0].Rows[i]["字段值"].ToString();
dsDelmnu=SqlExcute("tbmnuManage","DelMnu","Rs",false);在这判断一下ds的行数是多少?
你是怎么删的?是在SqlExcute中执行的吗?C#肯定可以的规的,只是你的方法设计的可能不是很合理。
to: mbh0210(独孤求败)
dsDelmnu=SqlExcute("tbmnuManage","DelMnu","Rs",false);这句话是删除菜单的,
我是一层一层删,从头到脚删,删一条判断下面有没有字菜单,有的话就返回一个dataset然后继续循环递归有子菜单的那群子菜单,反正慢复杂的呵呵!
to: Aallonlin(风之力)
四个字段组成的树形结构,是在 SqlExcute方法里面,调用存储过程删的,呵呵!谢谢大家关心了,不合理是在做递归时,致命伤,还好我的数据库是自己设计的,所以既然能用逸代输出,就一定能用递归删除了!汉!但是我设计结构的时候,就是和其他人不一样,
,但照样能执行!不过在操作时可能就没人家的简单!不知道是好处还是坏处!改不了了