如果真的很这么多的条件的话,我建议你用DropDownList把这些条件列出来.进行选择然后根据
文本框里的字段来进查询.如果你这样的话,查询一次不知要花费多长时间!!

解决方案 »

  1.   

    我是这么做的
    string SQLString="select E4_Workroom.Workroom_id,E4_Workroom.Workroom_class,DM_Dep.Dep_name,E4_Workroom.Workroom_date,DM_class.class_name,E4_Workroom.test_temp,E37_worker.Wor_name from E4_Workroom,DM_class,E37_worker,DM_Dep where E4_Workroom.class_id=DM_class.class_id and E4_Workroom.Workroom_oper_id=E37_worker.Wor_id and E4_Workroom.dep_id=DM_Dep.Dep_id and E4_Workroom.dep_id=(select DM_Dep.Dep_id from DM_Dep where DM_Dep.Dep_name='注塑车间') and DATEDIFF(day,E4_Workroom.Workroom_date,getdate())<=@Workroom_diff and E4_Workroom.Workroom_class like @Workroom_class and E4_Workroom.class_id=@class_id and E4_Workroom.Workroom_oper_id=@Workroom_oper_id and E4_Workroom.test_temp like @test_temp"; 
    SqlConnection myConnection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["DSN"]);
    DataSet ds = new DataSet();
    SqlDataAdapter myCommand = new SqlDataAdapter (SQLString, myConnection);
    myCommand.SelectCommand.Parameters.Add("@Workroom_class",SqlDbType.NVarChar,20).Value=DropDownList1.SelectedItem.Value;
    myCommand.SelectCommand.Parameters.Add("@Workroom_diff",SqlDbType.Int).Value=Dropdownlist2.SelectedItem.Value;
    myCommand.SelectCommand.Parameters.Add("@class_id",SqlDbType.NVarChar,20).Value=Dropdownlist3.SelectedItem.Value;
    myCommand.SelectCommand.Parameters.Add("@Workroom_oper_id",SqlDbType.NVarChar,20).Value=Dropdownlist4.SelectedItem.Value;
    myCommand.SelectCommand.Parameters.Add("@test_temp",SqlDbType.NVarChar,20).Value=Dropdownlist5.SelectedItem.Value;
    myCommand.Fill(ds);
    DataTable dt=ds.Tables[0];
    DataGrid1.DataSource=dt;
    DataGrid1.DataBind();
    myConnection.Close();