我想比较系统日期与我的SQL存储数据库日期使用查询在ASP.净c#
本文关键字:日期 查询 数据库 ASP 存储 比较 系统 SQL 我的 | 更新日期: 2023-09-27 18:16:16
我已经在SQL中存储了数据。有一个列"日期"与"DateTime"数据类型。现在我想使用查询比较系统日期和数据库日期。请帮忙的朋友提前致谢。
我试过这个代码,它显示了表的总数据。我想显示数据当前日期到最后3个月的数据我的表。(谢谢)
我已经试过了:
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
con.Open();
try
{
DateTime maxdate = DateTime.Now.Date;
DateTime mindate = DateTime.Now.Date.AddMonths(-3);
SqlDataSource1.SelectCommand = "select * from general1 where date<='" + maxdate + "' AND date>='" + mindate + "'" ;
假设您有一个控件绑定到示例代码中的SqlDataSource1
组件:
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString
SqlDataSource1.SelectCommand = "select * from general1 where date<= current_timestamp AND date>= dateadd(month, -3, current_timestamp)";
}