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;
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章