【问题标题】:Datetime comparison [duplicate]日期时间比较 [重复]
【发布时间】:2016-02-11 04:02:12
【问题描述】:

我的程序正在像这样从 SQL Server 读取数据:

if (!reader.IsDBNull(4))
{
    message.WazneDo = reader.GetDateTime(4);
}

此代码从 SQL Server 读取日期时间。然后我将它加载到datagridview:

WypozyczZwrocDb _dost1 = new WypozyczZwrocDb();
Global.listWypozyczZwroc = _dost1.PokazZar();
Global.fMain.Tabela.DataSource = Global.listWypozyczZwroc;

如何与今天的日期比较?我想改变行颜色。

我试过了:

DateTime dzis = DateTime.Now;

if(Tabela.Rows[Tabela.CurrentCell.RowIndex].Cells[4].Value > dzis)

if(Tabela.Rows[Tabela.CurrentCell.RowIndex].Cells[4].Value > dzis.ToString())

【问题讨论】:

    标签: c# sql-server datetime datagridview compare


    【解决方案1】:

    DateTime.Compare() 将允许您在基于返回的int 的条件语句中使用比较运算符。

    DateTime.Compare() msdn

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多