动态增加sql的select条件 有两个combobox,一个存stdid,一个存stdscore,两个都有一个all的值,现在我想有一条select语句,如果combobox1.text=="all"呢,就不把这个combobox加入到查询条件里去,否则呢就加一个 where stdid=combobox1.text该怎么写呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string sql="select * from yourtable where 1=1 {0}";string subsql="";if(combobox1.Text=="all") subsql="stdid="+bombobox1.Text;sql=string.Format(sql,subsql); //少写了个ANDstring sql="select * from yourtable where 1=1 {0}";string subsql="";if(combobox1.Text=="all") subsql=" and stdid="+bombobox1.Text;sql=string.Format(sql,subsql); 完全同意二楼观点,同时我觉得可以再简单点:string sql="select * from yourtable where 1=1";if(combobox1.Text=="all") sql += " and stdid="+bombobox1.Text; select * from yourtable where stdscore=(case stdscore when @score='' then stdscore else @score) and stuid=(case stdid when @id='' then stdid else @id) TextBox的输入控制 资源文件路径在报表参数中的 写法问题 请来帮忙 js 怎么判断RabioButton选中 先谢谢了 C#如何标记字符串中的关键字 一个SQL server统计问题 SOS,VS2005里我连接不上资源文件 我将窗体设成MDI,我想把主窗体的后面哪个滚动条给取消了怎么做 C# Winform 一个关于UPD发送命令的问题 请问怎么把源码编译成dll? -=来看看!=- 请高手给我一个很小很小的工厂模式编程的例子,谢谢 关于如何动态修改网页数据源的问题
string subsql="";
if(combobox1.Text=="all")
subsql="stdid="+bombobox1.Text;
sql=string.Format(sql,subsql);
string sql="select * from yourtable where 1=1 {0}";
string subsql="";
if(combobox1.Text=="all")
subsql=" and stdid="+bombobox1.Text;
sql=string.Format(sql,subsql);
string sql="select * from yourtable where 1=1";
if(combobox1.Text=="all") sql += " and stdid="+bombobox1.Text;