Search code examples
c#visual-studio-codeweb-applicationssqldataadapter

How to use 2 conditions at a time in Visual studio using sqlDataAdapter? I need to identify a value from Dropdownlist and also sort it using DateTime


SqlDataAdapter sqlda = new SqlDataAdapter(("SELECT Master_ID,Station,Job_ID,Conveyor,Andon_PC,Cast(Start_Time as time(2) )as Start_Time,Cast(Close_Time as time(2) )as Close_Time,Duration,Loss_Type,Loss_Description,Reason,Line_Name FROM Vehicle_Andon WHERE Reason IS NULL AND (Loss_Type IS NULL OR Loss_Type !=2) AND Line_Name =" + "'" + DropDownList1.SelectedValue + "'", sqlcon) + "Cast(Date_Time as date) = " + "'" + Date1.Value + "'" + "order by Date_Time desc", sqlcon);

sqlda.Fill(dtbl);

Solution

  • SqlDataAdapter sqlda = new SqlDataAdapter(("SELECT Master_ID,Station,Job_ID,Conveyor,Andon_PC,Cast(Start_Time as time(2) )as Start_Time,Cast(Close_Time as time(2) )as Close_Time,Duration,Loss_Type,Loss_Description,Reason,Line_Name FROM Vehicle_Andon WHERE Reason IS NULL AND (Loss_Type IS NULL OR Loss_Type !=2) AND Line_Name =" + "'" + DropDownList1.SelectedValue + "'") + "Cast(Date_Time as date) = " + "'" + Date1.Value + "'" + "order by Date_Time desc", sqlcon);
    
    sqlda.Fill(dtbl);