选择特定用户和部门的两个日期之间的数据。 [英] select the data between two date of perticular user and department.

查看:90
本文介绍了选择特定用户和部门的两个日期之间的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

但是当他们只选择了一个时它们正在工作但是当我选择两个之间的数据时,即一个是dept和其他日期,那么它显示该用户的所有数据,如果语句不起作用,则显示第二个和第四个之间的日期



这是我的代码



But they are working when only one is selected but when i select the data between two i.e one is dept and other date then it display the all data of that user and between the dates which means 2nd and 4th if statement is not working

here is my code

protected void btnreprt_Click(object sender, EventArgs e)
    {
        string date1 = Request.Form[txtdate1.UniqueID];
        string.Format("dd/MM/yyyy", date1);
        string date2 = Request.Form[txtdate2.UniqueID];
        string.Format("dd/MM/yyyy", date1);
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\site\SamsungClassifieds\App_Data\Dorknozzle.mdf;Integrated Security=True;User Instance=True");
        con.Open();
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        string search = "SELECT AD_TITLE, AD_DESC, AD_IMG, AD_PRICE, AD_NO, SUB_CAT_DESC, CAT_DESC, SELLER_NAME, SELLER_MOB_NO, SELLER_EMAIL_ID, SELLER_DEP, SELLER_FLOOR,DATE FROM AD_DETAIL_V WHERE BUY_SELL_ID='1' AND DELETED_AD='0'";
        if (txtemp.Text != "")
        {
            search = search + " and EMP_ID = '" + txtemp.Text + "'";
        }
        else if (txtemp.Text != "" & date1 != "" & date2 != "")
        {
            search = search + " and EMP_ID = '" + txtemp.Text + "'And Date between '" + date1 + "'and '" + date2 + "'";
        }
        else if (txtdept.Text != "")
        {
            search = search + " and SELLER_DEP = '" + txtdept.Text + "'";
        }
        else if (txtdept.Text != "" & date1 != "" & date2 != "")
        {
            search = search + " and SELLER_DEP = " + txtdept.Text + "And Date between '" + date1 + "'and '" + date2 + "'";
        }
        else if (date1 != "" & date2 != "")
        {
            search = search + "And Date between '" + date1 + "'and '" + date2 + "'";
        }
        cmd.CommandText = search;
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        result.DataSource = ds;
        result.DataBind();      
    }

推荐答案

以下列方式更改条件。



Change if condition in following way.

if (txtemp.Text != "")
{
    search = search + " and EMP_ID = '" + txtemp.Text + "'";
}

if (date1 != "" & date2 != "")
{
    search = search + " and Date between '" + date1 + "' and '" + date2 + "'";
}

if (txtdept.Text != "")
{
    search = search + " and SELLER_DEP = '" + txtdept.Text + "'";
}


指定这也可以给出答案



在第1个if语句中



if(txtemp.Text!=&& txtdate1.Text ==&& txtdate2.Text ==)


$ 3 $ b in 3 if语句



else if(txtdept.Text!=&& txtdate1.Text == && txtdate2.Text ==)
assign this can also give the answer

in 1st if statement

if (txtemp.Text != "" && txtdate1.Text == "" && txtdate2.Text == "")

in 3 if statement

else if (txtdept.Text != "" && txtdate1.Text == "" && txtdate2.Text == "")


这篇关于选择特定用户和部门的两个日期之间的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆