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";这条语句的记录集。
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";这条语句的记录集。
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 里的语句..
dt_menu是全局变量。