shay a

shay a

  • 2.1k
  • 70
  • 1.2k

using variables in Sqlite query c#

Dec 25 2021 7:30 PM

Hello,

I am trying get the values of a table in Sqlite from the last 2 days, this is my code:        

string dt = localDate.ToString("dd-MM-yyyy HH:mm");
string NewDate = localDate.AddDays(-2).ToString("dd-MM-yyyy HH:mm");

string query = "SELECT * FROM Offline WHERE Date <= '$dt' AND Date >= '$NewDate'";
SQLiteCommand myCommand = new SQLiteCommand(query, databaseObject.MyConnection);
databaseObject.OpenConnection();
SQLiteDataReader result = myCommand.ExecuteReader();

when I write the actual date and time in the query i get a result, but when i use the variables i get nothing, not even an error.

can you please help?

thank you.


Answers (3)