I have an Sqlite row createDate
in messages table. I want to retrieve all records from messages where createDate
is between startDate
and endDate
local variables in method.
Any suggestion, how to write query for string stm
? Or any other way how to do it
DateTime endDate = DateTime.Now;
DateTime startDate = endDate.AddDays(-7);
using (SQLiteConnection con = new SQLiteConnection(cs))
{
con.Open();
string stm = "SELECT * FROM messages WHERE createDate BETWEEN @startDate AND @endDate";
using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
{
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
for (j = 0; j <= rdr.FieldCount - 1; j++)
{
data = rdr.GetValue(j).ToString();
xlWorkSheet.Cells[i + 1, j + 1] = data;
}
i++;
}
}
}
con.Close();
}