sql.Append(" and tt.DateTime >='" + DateTime.Parse(this.requestMap["DateBeg"].ToString().Trim())+ "' ");
此处this.requestMap["DateBeg"]。Tostring()接收到的是年月日(即:2011-04-11),我想在后面手工加上时、分、秒(即2011-04-11 23:59:59)这样的话,我的sql.Append该如何完整写???

解决方案 »

  1.   

    我要sql.Append的完整格式,我也那样在后面加了,报格式错误?
      

  2.   

    sql.Append(" and tt.DateTime >='" + DateTime.Parse(this.requestMap["DateBeg"].ToString("yyyy-MM-dd HH:mm:ss").Trim())+ "' ");
      

  3.   

    sql.Append(" and tt.DateTime >='" + DateTime.Parse(this.requestMap["DateBeg"].ToString().Trim()+" 17:40:00").toString()+ "'");
    注意:" 17:40:00"开头应有一个空格
      

  4.   

    用参数来做比较好
    SqlParameter par1 = new SqlParameter();
                par1.DbType = System.Data.DbType.DateTime;
                par1.ParameterName = "@TimePara";
                par1.Value =new DateTime(year, month,day,hour,minute, second);
      

  5.   

    不行,把你那个时间转化为秒数,例如:00:10:20是620秒,再用AddSeconds方法加上
    DateTime mydt = sql.requestMap["DateBeg"];
    DateTime myt = mydt.AddSeconds(2000); 然后sql.Append(" and tt.DateTime >='" + myt+ "' ");
      

  6.   

    还不对,是
    不行,把你那个时间转化为秒数,例如:00:10:20是620秒,再用AddSeconds方法加上
    DateTime mydt = sql.requestMap["DateBeg"];
    DateTime myt = mydt.AddSeconds(620);  然后sql.Append(" and tt.DateTime >='" + myt.toString()+ "' ");
      

  7.   

    sql.Append(" and tt.DateTime >='" + DateTime.Parse(this.requestMap["DateBeg"].ToString(yyyy-MM-dd))+ "' 23:59:59");