当前位置: 代码迷 >> .NET Framework >> 时间段和其它的字段一起查,该如何解决
  详细解决方案

时间段和其它的字段一起查,该如何解决

热度:56   发布时间:2016-05-02 01:01:57.0
时间段和其它的字段一起查
时间段和其它的字段一起查,单写一个我可以写的出来,但是两个一起写就不会,新人求教,求教怎么组合起来一起查

查时间段代码

C# code
int sun = 0;            double sum = 0;            string sql = "select * from Users where Dates between #" + this.DtXsrq.Value.ToString() + "# and #" + this.nosql.Value.ToString() + "#";            DataSet ds = DBHepler.GetDataSet(sql);            dataviwe.DataSource = ds.Tables[0].DefaultView;



查寻多个字段的
C# code
StringBuilder sb = new StringBuilder();            sb.Append("select * from Users A where 1=1");            if (comsheng.Text != "")            {                sb.Append("and A.Province='" + comsheng.Text + "'");            }            if (comshi.Text != "")            {                sb.Append("  and A.City='" + comshi.Text + "'");            }            if (txtxue.Text != "")            {                sb.Append("  and A.District='" + txtxue.Text + "'");            }            if (txtzhen.Text != "")            {                sb.Append("  and A.Town='" + txtzhen.Text + "'");            }            if (txtname.Text != "")            {                sb.Append("  and A.Name='" + txtname.Text + "'");            }            if (comProduct.Text != "")            {                sb.Append(" and A.Product='" + comProduct.Text + "'");            }            string sql = sb.ToString();             DataSet ds = DBHepler.GetDataSet(sql);             dataviwe.DataSource = ds.Tables[0].DefaultView;


------解决方案--------------------
C# code
int sun = 0;            double sum = 0;            string sql = "select * from Users where Dates between #" + this.DtXsrq.Value.ToString() + "# and #" + this.nosql.Value.ToString() + "#";             if (comsheng.Text != "")            {                sql += (" and A.Province='" + comsheng.Text + "'");            }            DataSet ds = DBHepler.GetDataSet(sql);            dataviwe.DataSource = ds.Tables[0].DefaultView;
  相关解决方案