0

到目前为止,我已经编写了这段代码,它适用于我正在做的事情,但是如果我搜索 6 月 13 日,它只会查找到 6 月 12 日,有人可以帮我弄清楚我的代码有什么问题吗?或者我可以在哪里添加一天的间隔?我试过了,它只是不适合我。

var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var fromDate= "";
var toDate= "";

    formSSO = Request.QueryString["formSSO"];
    fromDate = Request.QueryString["fromDate"];
    toDate = Request.QueryString["toDate"];


selectCommand = "(SELECT * from RMS WHERE SSO LIKE @0)";


if(!Request.QueryString["fromDate"].IsEmpty() ) {
    selectCommand = "SELECT * FROM RMS WHERE SSO LIKE @0 AND Created BETWEEN @1 AND @2";
}

if(Request.QueryString["formSSO"].IsEmpty() ) {
    <div class="simple"><strong>*SSO ID is Required.</strong></div>

}
var data = db.Query(selectCommand, formSSO, fromDate, toDate);
var columns = new[]{"ID", "SSO", "Category", "System", "Subject", "Created"};
var grid = new WebGrid(data, ajaxUpdateContainerId: "grid", defaultSort: "ID", columnNames: columns);
if (Request.QueryString[grid.SortDirectionFieldName].IsEmpty()) {
grid.SortDirection = SortDirection.Descending;
}
}
4

1 回答 1

0

您可以尝试的一件事是使用 <= 和 >= 而不是像这样的 BETWEEN:

selectCommand = "SELECT * FROM RMS WHERE SSO LIKE @0 AND Created >= @1 AND Created <= @2";

我希望这能解决问题!

如果不是,您也可以强制将日期推迟到未来一天,然后使用 BETWEEN 运算符,就像您现在这样:

            DateTime to_date = Convert.ToDateTime(to_date_string);
            to_date = to_date.AddDays(1);
            to_date_string = to_date.ToString();
于 2013-06-14T17:44:19.133 回答