问题标题不清楚,但是通过我的以下描述,这个问题非常清楚:
我在 CREATE TABLE 查询中有一个声明为 datetime 的字段BirthDay
,如果我有以下查询并像这样填写 DataTable,我称之为该字段:
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT BirthDay FROM myTable", myConnection);
DataTable dt = new DataTable();
da.Fill(dt);
myDataGridView.DataSource = dt;
的列BirthDay
有myDataGridView
类型,DateTime
我可以通过 myDataGridView.Columns["BirthDay"].ValueType
.
但是,如果我像这样更改 SELECT 查询:
SQLiteDataAdapter da = new SQLiteDataAdapter("SELECT CASE WHEN 1 THEN BirthDay END AS BirthDay2 FROM myTable", myConnection);
我希望在填写我的 DataTable 并绑定到 myDataGridView 之后,该BirthDay2
列也是类型。DateTime
但是类型是System.Object
?
我试过了,CAST(... as DATETIME)
但返回的类型是System.Int64
(我知道 SQLite 中的 DATETIME 实际上对应Int64
于 .NET 中的),我想知道如何让它System.DateTime
作为原始列返回BirthDay
。
我需要最终类型(可以通过 进行检查DataGridViewColumn.ValueType
),DateTime
以便我可以使用DataGridViewColumn.Format
我想要的格式来格式化我的日期时间字符串。
您的帮助将不胜感激!