【问题标题】:How to display a Date-Value from a DataReader in a TextBox如何在文本框中显示来自 DataReader 的日期值
【发布时间】:2021-06-05 10:45:49
【问题描述】:
 Date.Text = reader["dateintable"].ToShortDateString();

我想从 sql 表中获取日期值并使用 executereader 将其显示在文本框中

【问题讨论】:

    标签: c# sql asp.net


    【解决方案1】:

    如果您有DateTime,则可以使用ToShortDateString。但你只有一个Object。你需要投射它:

    Date.Text = ((DateTime)reader["dateintable"]).ToShortDateString();
    

    另一种方法是使用GetDateTime,但首先需要列索引:

    Date.Text = reader.GetDateTime(reader.GetOrdinal("dateintable")).ToShortDateString();
    

    【讨论】:

      猜你喜欢
      • 2014-06-25
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多