StringBuilder   sql1   =   new StringBuilder( "select top "+15*CurrentPage+" WTPROD,WTTOOL from  I_ToolPlan  where 1=1 ");  if(a !="" )   

sql1.Append( " and WTPROD between '"+a+"' and '"+b+"'  ");

if(c != "")   
{
sql1.Append(" and WTTOOL between '"+c+"'  and  '"+d+"'");
}
sql1.Append("order by WTTOOL desc ");
StringBuilder   sql2   =   new StringBuilder( "Select Top  15 x.* from I_ToolPlan x left join  ("+sql1+")y on x.WTPROD=y.WTPROD and x.WTTOOL=y.WTTOOL   where 1=1 ");  if(a != "" )   

sql2.Append( " and x.WTPROD between '"+a+"' and  '"+b+"'  ");

if(c != "")   
{
sql2.Append(" and x.WTTOOL  between '"+c+"'  and  '"+d+"'");
}
sql2.Append("and y.WTTOOL is null order by x.WTTOOL desc");
 SqlDataAdapter MyAdapter = new SqlDataAdapter(p_wsp, MyCon());
 MyAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;这样调用存储过程,但是存储过程里面有两条select语句,SqlDataAdapter(p_wsp, MyCon());会执行那条语句?

解决方案 »

  1.   

    MyAdapter  fill一个dataset就可以把两条select的结果都取出来了
      

  2.   

    怎样把这段sql改成存储过程?看题目啊。。
    StringBuilder   sql1   =   new StringBuilder( "select top "+15*CurrentPage+" WTPROD,WTTOOL from  I_ToolPlan  where 1=1 ");                 if(a !="" )   
                    { 
                        sql1.Append( " and WTPROD between '"+a+"' and '"+b+"'  ");    
                    } 
                    if(c != "")   
                    {
                        sql1.Append(" and WTTOOL between '"+c+"'  and  '"+d+"'");                
                    }    
                    sql1.Append("order by WTTOOL desc ");
                    StringBuilder   sql2   =   new StringBuilder( "Select Top  15 x.* from I_ToolPlan x left join  ("+sql1+")y on x.WTPROD=y.WTPROD and x.WTTOOL=y.WTTOOL   where 1=1 ");                 if(a != "" )   
                    { 
                        sql2.Append( " and x.WTPROD between '"+a+"' and  '"+b+"'  ");
                    } 
                    if(c != "")   
                    {    
                        sql2.Append(" and x.WTTOOL  between '"+c+"'  and  '"+d+"'");
                    }
                    sql2.Append("and y.WTTOOL is null order by x.WTTOOL desc");
      

  3.   

    改的还是拼接SQL,
    返回两个select结果集