日期:2014-05-20  浏览次数:20724 次

时间段和其它的字段一起查
时间段和其它的字段一起查,单写一个我可以写的出来,但是两个一起写就不会,新人求教,求教怎么组合起来一起查

查时间段代码

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;