这样吧,用for读出选中的,放在数组中,
然后判断数组个数,得出是单选还是双选,
然后,相关查询就可以了
然后判断数组个数,得出是单选还是双选,
然后,相关查询就可以了
解决方案 »
- ASP.NET不能写入事件怎么回事?
- Chart 控件 的列显示的问题!
- 100分求建站详细流程
- SqlHelper.ExecuteNonQuery更新问题....急急急!!
- 个人要开个人才网,需要做些什么准备呢
- 农历转换阴历的源代码(急急急急急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!)
- 急急急急急急急急急急急急急急---如何让datalist和xml绑定?
- 紧急:web.config 中 <allow roles="admin"> 中的 admin 是什么的角色?
- 关于ASP.NET中连接Oracle的问题(用ODBC.NET方式)
- 在字符串中我如何取出我所需要的字符串??
- RadioButton 的Enable属性与disalbed 客户端属性
- asp.net效果实现
我不这样认为啊,你判断它选中的个数,如果一个,就单个查询,如果是二个,就查询,如果是三个,得到三个的值,就按三个查询。
用for查询,代码简单,取值方便
for(int i=0; i<300,i++)
{
//有没有选中,有就传出值(i)
}
按照你那个写法 ,比如返回是1,5 或者15,25,35...
判断应该怎么判断? 我想的是:2个参数SQL的条件就是 X and X,3个就是x adn x and x ,.....300个以此类推
SQL语句写的时候该怎么写呢?
for (int i = 0; i < 300; i++ )
{
if (CheckBox1.Checked)
{
int i = 0;
st[i]=CheckBox1.Text.ToString();
i=i+1;
}
}
int int_st=st.Length;
int_st是多少就为多少查询
查询的值就是数值那儿,要用就调了出来
for(int i=0;i<st.Length;i++)
{
string a=st[i];
a=a+"and"+ st[i];
}
类似这样子,得到字符串,具体,你仔细想想,由于工作关系,不能细想,写出来,楼主自己想相
大哥 你这个代码 返回的是传过来多少个参数, 你意思是不是是,返回一个数组,再取出数组的值,把数组取出的值传进SQL语句?
那SQL应该怎么写呢??? 我以前写过一个5个参数的,先new 一个选择框
foreach循环读取数据绑定选择框
最后在用foreach读取已经选择的框。。,因为可能出现的情况太多了,
5个参数我判断+拼SQL就用了150行代码呢,现在我有300多个参数呢~~~~
还是这个改进后就是15楼的那个循环?
if (jid == -1 && xid == -1 && rid == -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid == -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid != -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where r_id=" + rid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid == -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid == -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid == -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid == -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid != -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and r_id=" + rid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid != -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and r_id=" + rid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid == -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid != -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and r_id=" + rid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid != -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and r_id=" + rid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid != -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and r_id=" + rid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid == -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid == -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
//
if (jid != -1 && xid != -1 && rid != -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and r_id=" + rid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid == -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid == -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid == -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid != -1 && rid != -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and x_id=" + xid + " and r_id=" + rid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid != -1 && xid == -1 && rid != -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where j_id=" + jid + " and r_id=" + rid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid != -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " and r_id=" + rid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid != -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where r_id=" + rid + " and verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid == -1 && verifyid != -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where verifyid=" + verifyid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid != -1 && verifyid == -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " and r_id=" + rid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid != -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " and r_id=" + rid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid != -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where r_id=" + rid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid == -1 && verifyid != -1 && shpid == -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " and verifyid=" + verifyid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid == -1 && rid != -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where r_id=" + rid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
if (jid == -1 && xid != -1 && rid == -1 && verifyid == -1 && shpid != -1)
{
string sql = "select * from JW_4_4 where x_id=" + xid + " and shpid=" + shpid + " order by id desc";
Bind(sql, con);
}
求建议~
谢谢给我建议,不不知道SQL语句的条件怎么生成麻烦说下 好么~~~~
一个参数的
string sql=null;
if(checkbox1.checked){
sql="select * from Table1 where 参数=1 ";
}
其他一个的参数一样类似...
二个参数的判断
if(checkbox1.checked&& checkbox2.checked){ sql="select * from Table1 where 参数=1 and 参数=2";
}
以此类推 还是跟我那个想法一样我感觉语句只能这样写,有没有简单的办法?
example:字典dictionary{key:参数一,value:"file";key:参数二 ,value:"name"};sql语句条件部门 sqlstring;
//每次选择参数都会触发
选择参数事件
{
这里用一个list<dictionary[key].value>记录选择过的参数
if(list.contain(key)
{
删除sql语句中一个部分的方法(dictionary[key].value)
}
else
{
key 通过选择参数穿过来 肯定可以得到选择的参数的名字
组合sql语句方法(dictionary[key].value)
list.add(dictionary[key].value);
}
}
组合sql语句方法(dictionary.value)
{
//组合逻辑
sqlstring += dictionary.value
}
删除sql语句方法(dictionary.value)
{
//删除逻辑
sqlstring += dictionary.value
}
int int_st=st.Length;
for(int i=0;i<st.Length;i++)
{
string sql="select * from Table1 where 参数=1 "
sql=sql+“and”+st[i]; }
这样子for输出一个字符串语句
foreach(checkbox c in page.controls)
{
if(c.checked)
{
varstring+="c条件";
}
}
用varstrings查询
{
List<String> values = new List<string>(); foreach (ListItem item in listCtrl.Items)
{
if (item.Selected) values.Add(item.Value);
} return values.ToArray();
}
获取到所有的选中的框后,再根据选中框的value来对应你的参数,至于如何将你的checkbox和参数之间作映射,看实际情况了
那样循环出来后 SQL语句是不是这样写:取出数组选中的,进行判断,省略了~~
string sql=null;
if(checkbox1.checked){
sql="select * from Table1 where 参数=1 ";
}
其他一个的参数一样类似...
二个参数的判断
if(checkbox1.checked&& checkbox2.checked){ sql="select * from Table1 where 参数=1 and 参数=2";
}
以此类推 还是跟我那个想法一样我感觉语句只能这样写,有没有简单的办法?
就
String sql = "select * from tb where id in ("+ String.Join(",",GetSelectedValues(listCheckBox)) + ")";
checkbox2.value="参数=2"
checkbox3.value="参数=300"
那么就是
String sql = "select * from tb where ("+ String.Join(" and ",GetSelectedValues(listCheckBox)) + ")";
你不可能 在 前台拖放 300个控件 慢慢弄吧 ,费时费力, 不好管理
<asp:CheckBoxList ID="CheckBoxList1" DataTextField="FiledName" DataValueField="Value" runat="server">
</asp:CheckBoxList> <%
<asp:CheckBoxList ID="CheckBoxList1" DataTextField="FiledName" DataValueField="Value" runat="server">
<asp:ListItem Text="jid" Value="jid=jid" ></asp:ListItem>
<asp:ListItem Text="sid" Value="sid=sid" ></asp:ListItem>
</asp:CheckBoxList>%>
或者建一张表
ID Value 查询条件
前台 Value:<input type="checkbox" name="NAME相同" value="ID">
获取 ID字符串,写个存储过程,拆分ID字符串,拼接每个ID对应的条件,存储过程中获取返回记录集,这样效率会高些吧
2.在查询页面,选择1,3,5,选择项目,得到对应 代码101010,与110101做AND运算,得到100000,说明满足条件1,只要运算中间有1就行,说明这条记录是满足你查询的条件的,因为你是或的关系,只要满足一个条件就行。如果是且的关系可以用其他的运算,再大的记录数量也不会速度很慢,主要扫描1次表结构。
2.然后勾选你要对比的参数选项
3.用js获取你选中的checkbox 每个checkbox的value ="对比的参数"
4.获取选中的checkbox的值
通过列表绑定字段,通过下拉框选择条件=,>,<,!=等,或通过JS添加条件
实现多条件查询
string sql="";
sql+=条件?"":"";