简体   繁体   中英

How do I get a DateTime value from sqlite row in c#

I have read many questions on here that dont quite give the solution and I have tried many variations of using the sqlite datetime(...) or strftime() (though not sure if the latter is recognized in c#), to try an extract a set of column values from a single row but the date fields are returning nothing string and numerics columns are fine. As evidenced by inspecting a watch dt.Rows[0]["ResponseDateTime"] Can anyone point out where I have gone wrong? have tried: (amongst others)

Select field1, strftimetime('%d/%m/%Y %H:%M',resDateTime) as ResponseDateTime, field2 from table

Select field1, datetime(resDateTime), field2 from table

etc

public DataTable GetDataTable(string sql)
{
    DataTable dt = new DataTable();
    try
    {
    //with the following the date field is not getting any date datat into the field
    //  SQLiteConnection cnn = new SQLiteConnection(dbConnection);
    //  SQLiteCommand command = new SQLiteCommand(sql, cnn);
    //  cnn.Open();
    //  SQLiteDataAdapter myAdapter = new SQLiteDataAdapter(command);
    //  myAdapter.Fill(dt);

            SQLiteConnection cnn = new SQLiteConnection(dbConnection);
            cnn.Open();
            SQLiteCommand dbCommand = cnn.CreateCommand();
            dbCommand.CommandText = sql;

            SQLiteDataReader executeReader = dbCommand.ExecuteReader(CommandBehavior.SingleResult);
            dt.Load(executeReader); // <-- FormatException

            cnn.Close();
        }
        catch (Exception crap)
        {
            OutCrap(crap);
            //throw new Exception(crap.Message);

        }
        return dt;
    }

Aha 从数据库IOS的日期之间获取与相关的sqlite提取日期相关的问题,事实上,在进行了所有更改之后, IOS回答了这个问题!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM