4个回答
展开全部
private void btntianjia_Click(object sender, EventArgs e)
{
//拼接查询条件
string conditon = string.Empty;
if (rdoDuan.Checked)//选择时间段
{
conditon += string.Format(" consumedate>='{0}' and consumedate<='{1}'", cboYear.Text + "-" + cboMonth.Text + "-" + cboDay.Text, cboEndYear.Text + "-" + cboEndMonth.Text + "-" + cboEndDay.Text);
}
else//时间点
{
conditon += string.Format(" consumedate='{0} ' ", cboYear.Text + "-" + cboMonth.Text + "-" + cboDay.Text);
}
//按类别查询
if (conditon != string.Empty)
{
string category = string.Empty;
if (cbGongZi.Checked)
{
category += string.Format("'{0}',", cbGongZi.Text);
}
if (cbYuLe.Checked)
{
category += string.Format("'{0}',", cbYuLe.Text);
}
if (cbYinShi.Checked)
{
category += string.Format("'{0}',", cbYinShi.Text);
}
if (cbOtherRu.Checked)
{
category += string.Format("'{0}',", cbOtherRu.Text);
}
if (cbFuZhuang.Checked)
{
category += string.Format("'{0}',", cbFuZhuang.Text);
}
//去掉最后一个多余的逗号
string categoryFina = category.Substring(0, category.Length - 1);
conditon += string.Format(" and type in({0})", categoryFina);
//金额范围
double minMoney = 0, maxMoney = 0;
if (txtMin.Text.Trim() == string.Empty)
{
txtMin.Text = "0";
}
if (txtMax.Text.Trim() == string.Empty)
{
txtMax.Text = "0";
}
try
{
minMoney = Convert.ToDouble(txtMin.Text.Trim());
maxMoney = Convert.ToDouble(txtMin.Text.Trim());
}
catch (FormatException ex)
{
MessageBox.Show("请输入有效的金额");
return;
}
if (minMoney > 0)
{
conditon += string.Format(" and consumemoney >={0} ", txtMin.Text);
}
if (maxMoney > 0)
{
conditon += string.Format(" and consumemoney <={0} ", txtMax.Text);
}
//备注的模糊搜索
if (txtDescription.Text.Trim() != string.Empty)
{
conditon += string.Format(" and Descrition like '%{0}%'", txtDescription.Text.Trim());
}
}
{
//拼接查询条件
string conditon = string.Empty;
if (rdoDuan.Checked)//选择时间段
{
conditon += string.Format(" consumedate>='{0}' and consumedate<='{1}'", cboYear.Text + "-" + cboMonth.Text + "-" + cboDay.Text, cboEndYear.Text + "-" + cboEndMonth.Text + "-" + cboEndDay.Text);
}
else//时间点
{
conditon += string.Format(" consumedate='{0} ' ", cboYear.Text + "-" + cboMonth.Text + "-" + cboDay.Text);
}
//按类别查询
if (conditon != string.Empty)
{
string category = string.Empty;
if (cbGongZi.Checked)
{
category += string.Format("'{0}',", cbGongZi.Text);
}
if (cbYuLe.Checked)
{
category += string.Format("'{0}',", cbYuLe.Text);
}
if (cbYinShi.Checked)
{
category += string.Format("'{0}',", cbYinShi.Text);
}
if (cbOtherRu.Checked)
{
category += string.Format("'{0}',", cbOtherRu.Text);
}
if (cbFuZhuang.Checked)
{
category += string.Format("'{0}',", cbFuZhuang.Text);
}
//去掉最后一个多余的逗号
string categoryFina = category.Substring(0, category.Length - 1);
conditon += string.Format(" and type in({0})", categoryFina);
//金额范围
double minMoney = 0, maxMoney = 0;
if (txtMin.Text.Trim() == string.Empty)
{
txtMin.Text = "0";
}
if (txtMax.Text.Trim() == string.Empty)
{
txtMax.Text = "0";
}
try
{
minMoney = Convert.ToDouble(txtMin.Text.Trim());
maxMoney = Convert.ToDouble(txtMin.Text.Trim());
}
catch (FormatException ex)
{
MessageBox.Show("请输入有效的金额");
return;
}
if (minMoney > 0)
{
conditon += string.Format(" and consumemoney >={0} ", txtMin.Text);
}
if (maxMoney > 0)
{
conditon += string.Format(" and consumemoney <={0} ", txtMax.Text);
}
//备注的模糊搜索
if (txtDescription.Text.Trim() != string.Empty)
{
conditon += string.Format(" and Descrition like '%{0}%'", txtDescription.Text.Trim());
}
}
展开全部
自己灵活变通下 给你个例子
string strSql = "select * from tb_News where style='" + this.ddlStyle.SelectedValue.ToString() + "'";
strSql += " and (( content like '%" + this.txtKey.Text + "%')";
strSql += " or (Title like '%" + this.txtKey.Text + "%'))";
说明:数据表:tb_News 字段:style(样式) content(内容) Title(标题)
ddlStyle.SelectedValue 下拉菜单选择样式
txtKey.Text 文本框的值
string strSql = "select * from tb_News where style='" + this.ddlStyle.SelectedValue.ToString() + "'";
strSql += " and (( content like '%" + this.txtKey.Text + "%')";
strSql += " or (Title like '%" + this.txtKey.Text + "%'))";
说明:数据表:tb_News 字段:style(样式) content(内容) Title(标题)
ddlStyle.SelectedValue 下拉菜单选择样式
txtKey.Text 文本框的值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System.Text.RegularExpressions;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有很多条件吗?
那你就拼sql语句吧!
那你就拼sql语句吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询