sql 几个条件查询方法

后台:

      

      decimal ass_id = string.IsNullOrEmpty(tbid.Text) ? 0 : decimal.Parse(tbid.Text.Trim());//判断有无
        DateTime? startime = null, endtime = null;
        if (!string.IsNullOrEmpty(tbbigtime.Text))
            startime = DateTime.Parse(tbbigtime.Text.Trim());
        if (!string.IsNullOrEmpty(tbendtime.Text))
            endtime = DateTime.Parse(tbendtime.Text.Trim());

 

        DataSet ds = moneymanager.PMoneyListGet(ass_id, startime, endtime);//绑定方法

 

 

 

 

BLL层:

         public DataSet PMoneyListGet(decimal ass_id, DateTime? startime, DateTime? endtime)
        {
            return moneyservice.PMoneyListGet(ass_id, startime, endtime);
        }

 

 

 

 

 

DAL层:

 

 

         public DataSet PMoneyListGet(decimal ass_id, DateTime? startime, DateTime? endtime)
        {
            string query=string.Empty;
            if (ass_id > 0)
                query += string.Format(" and ass_id={0}", ass_id);
            if (startime != null && endtime != null && startime <= endtime)
                query += string.Format(" and (trd_dtm>='{0}' and trd_dtm<='{1}')", startime, endtime);
            string sql = string.Format("select * from cc_money_rec where 1=1 " + query + " order by trd_dtm desc");

            DataSet ds = null;
            try
            {
                ds = DBHelper.GetDataSet3(sql, "money_rec");

            }
            catch (SqlException se)
            {

                throw new Exception(se.Message, se);
            }

            return ds;
        }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值