当只输入房间号(RoomID)点查找时,得到相关数据
当只输入类型(RoomType)时点击查找,得到相关数据
当只输入楼层(RoomPosition)时点击查找,得到相关数据
当只输入人数(PersonNum)时点击查找,得到相关数据
当是输入备注(RoomRemark)时点击查找,得到相关数据
当全部都输入时,得到相关数据
数据绑定到listView控件
小弟不才,试了好多次,脑细胞死伤无数,所以还承蒙各位高手指点,并给出详细代码。谢谢
当只输入房间号(RoomID)点查找时,得到相关数据
当只输入类型(RoomType)时点击查找,得到相关数据
当只输入楼层(RoomPosition)时点击查找,得到相关数据
当只输入人数(PersonNum)时点击查找,得到相关数据
当是输入备注(RoomRemark)时点击查找,得到相关数据
当全部都输入时,得到相关数据
数据绑定到listView控件
小弟不才,试了好多次,脑细胞死伤无数,所以还承蒙各位高手指点,并给出详细代码。谢谢
string sql = "select * from v_topic"; string key = ""; if (TextBox1.Text != "") key = "topicname like '%" + getSafestring(TextBox1.Text) + "%'"; if (Checkshowhide.Checked) { if (TextBox2.Text != "") { if (key == "") key = "uid like '%" + getSafestring(TextBox2.Text) + "%'"; else key += " and uid like '%" + getSafestring(TextBox2.Text) + "%'"; } if (RadioButton2.Checked) { if (key == "") key = "state=1"; else key += " and state=1"; } if (RadioButton3.Checked) { if (key == "") key = "state=2"; else key += " and state=2"; } if (DropDownList1.SelectedItem.Text != "全部时间") { if (RadioButton4.Checked) { if (key == "") key = "emittime > '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; else key += " and emittime > '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; } else { if (key == "") key = "emittime < '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; else key += " and emittime < '" + DateTime.Now.AddDays(-int.Parse(DropDownList1.SelectedValue)) + "'"; } } if (RadioButton6.Checked) { key += " order by " + DropDownList2.SelectedValue; } else { key += " order by " + DropDownList2.SelectedValue + " desc"; } } if (key != "") sql += " where " + key;
给一段实例,你只要类似更换textbox的名称即可
select * from 你的表名 where RoomID=@roomid
添加参数到SQlCommand中,你可以将查询的结果放到一个dataset中,然后设置listview的datasource=你定义的dataset,最后调用一下listview.databind(); 方法就绑定了。