如何使用reader.GetDateTime(i)从sqlite数据库获取DateTime?

时间:2018-11-09 09:28:38

标签: c# sqlite

string sql = "select * from User where sUserName = '" + sUserName + "' AND sUserPassword = '" + sUserPassword + "'";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
if (reader.Read())
{
    DateTime Time = reader.GetDateTime(0);
    System.DateTime timeNow_FromLocal = System.DateTime.Now; 
    if (timeNow_FromLocal < Time)
    {
        return true;
    }
    else
    {
        return false;
    }
}
else
{
    return false;
}

我想从sqlite数据库中获取DateTime以与系统时间进行比较,但是我无法成功reader.GetDateTime(0)

1 个答案:

答案 0 :(得分:0)

尝试

DateTime Time = DateTime.Parse(reader["columnName"].ToString());