对于C#的开发的网页程式,一些企业或者工厂可能会运用这些程式去查询一些资料,考虑到查询的资料太多,假如一个月的资料就有上万条数据,在对于查询资料的SQL语句后时间栏位运用Between.....AND......对查询时间范围进行控制,以免捞取数据太多,查询时间较长。
根据判断输入的时间范围返回的结果是True或者FALSE来进行处理。已限制一个月(30天)的查询时间为例,代码如下:
private bool CheckDateTimeScope()
{
DateTime FD = Convert.ToDateTime(Param.InForm.Value);
DateTime ED = Convert.ToDateTime(Param.InEnd.Value);
if (((TimeSpan)(ED - FD)).Days < 30)
{
return true;
}
else
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alertForm", "alert('Start Date to End Date Must not Large than 30 days ! ');", true);
return false;
}
}
本文来自博客园,作者:農碼一生,转载请注明原文链接:https://www.cnblogs.com/wml-it/p/12132835.html
技术的发展日新月异,随着时间推移,无法保证本博客所有内容的正确性。如有误导,请大家见谅,欢迎评论区指正! 个人开源代码链接: GitHub:https://github.com/ITMingliang
Gitee:https://gitee.com/mingliang_it
GitLab:https://gitlab.com/ITMingliang
进开发学习交流群:![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicGcq5Ce2hjM0QTNwgTM4ATMy8Fdvw1N2YDM2cTMvwFdp1Cbtd3Lc12bj91cn9Gbi52YvwVbvNmLzd2bsJmbj5ycldWYtl2Lc9CX6MHc0RHaiojIsJye.jpg)