例如最近3天,最近一周,最近半年,刚学习,多谢~

解决方案 »

  1.   

    public DataTable SelWhere(string joinName,string startDate,string endDate,string type)
    {
    string start="";
    string end="";
    string thistype="";
    if(startDate.Trim()!="")
    start=" and InsertDate>@startDate ";
    if(end.Trim()!="")
    end=" and InsertDate<@endDate ";
    if(type.Trim()=="")
    type="4";
    if(type.Trim()!="4")
    thistype=" and type=@type ";
    string strSql=@"select * from T_CivilSoldierMoney  where name like '%"+@joinName+"%' "+thistype+start+end;
    SqlParameter[] Params = new SqlParameter[4];
    Params[0] = new SqlParameter("@joinName",joinName );
    Params[1] = new SqlParameter("@startDate", startDate );
    Params[2] = new SqlParameter("@endDate", endDate );
    Params[3] = new SqlParameter("@type", type );
    return  EraData3.Select(strSql,Params);
    }
      

  2.   

    dim cmd as new sqlcommand("select * from tablename where posttime>@time",cnn)
    dim myTime as string
    if listbox1.selectedindex=1 then
    myTime=Now.AddDays(-3).ToString
    else if .....
    myTime=Now.AddDays(-6).ToString...
    end ifcmd.parameters.add("@time",myTime)
      

  3.   

    sql里
    用 GetDate()获取当前日期,
    如果要最近七天的,可以 GetDate() - 7   就是了。