[英]How do I insert and query a DateTime object in SQLite DB from C#?
[英]How do I get a DateTime value from sqlite row in c#
我在這里閱讀了很多問題,並沒有給出解決方案,並且我嘗試了使用sqlite datetime(...)或strftime()的多種嘗試(盡管不確定后者是否在c#中被識別),以嘗試提取數據一組來自單行的列值,但日期字段未返回任何字符串,而數字列也很好。 通過檢查手表可以證明dt.Rows [0] [“ ResponseDateTime”]誰能指出我哪里出了問題? 曾嘗試過:(以及其他)
從表中選擇字段1,strftimetime('%d /%m /%Y%H:%M',resDateTime)作為ResponseDateTime,字段2
從表中選擇field1,datetime(resDateTime),field2
等等
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回答了這個問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.