private DataTable dt_Readmenu(string str_type){
            string StrSql_Menu;
            if (str_type != "A")
            {
                StrSql_Menu = "select  * from cy_A  where leibie ='" + str_type + "'  order by  bh_cs";
            }else
            { 
                StrSql_Menu = "select  * from cy_A order by  bh_cs";
            }
            SqlCommand mycom = new SqlCommand(StrSql_Menu, mycon);
            mycon.Open();
            SqlDataAdapter mydr = new SqlDataAdapter(mycom);
            mydr.Fill(dt_menu);
            mycon.Close();
            GC.Collect();
            return dt_menu;
        }
我运行这个函数,为什么他都是执行第一次的“StrSql_Menu ”为准?
如:该函数第一次运行StrSql_Menu = "select  * from cy_A  where leibie ='" + str_type + "'  order by  bh_cs";
    当第二次我再用到该函数的时候 StrSql_Menu = "select  * from cy_A order by  bh_cs";
   为什么还是得到的结果还是"select  * from cy_A  where leibie ='" + str_type + "'  order by  bh_cs";这条语句的记录集。

解决方案 »

  1.   

    条件的事呗,你的条件是A,他就执行select  * from cy_A  where leibie ='" + str_type + "'  order by  bh_cs";
      

  2.   

    看你的判断条件...
    if (str_type != "A") 
                { 
                    StrSql_Menu = "select  * from cy_A  where leibie ='" + str_type + "'  order by  bh_cs"; 
                }else 
                { 
                    StrSql_Menu = "select  * from cy_A order by  bh_cs"; 
                } //代码跟进去看一看,如果你第二次调用的时候 str_type 不为A还是会取if 里的语句..
      

  3.   

    dt_menu是全局的吗?可以重新new一个或者重新初始化下 ,然后你再看下结果
      

  4.   

     if 中的条件确定没有错误!
      
      dt_menu是全局变量。
      

  5.   

    dt_menu实例化就行了啊  谢谢