Good evening everyone. First question. How to choose the desired day and time to show the report? I want when choosing a date you need to show the amount of this day. Question two: Where will the result of the query be saved and how can I take this result? Thanks in advance.

Code:

private void buttonProfit_Click(object sender, EventArgs e) { string query = "SELECT SUM(TotalSum) FROM TotalOutcomes WHERE Date_Time BETWEEN @dateBefore AND @dateAfter"; try { connection.Open(); command = new SQLiteCommand(query,connection); command.Parameters.AddWithValue("@dateBefore",dateTimePickerBeforeTotalOutcomes.Value.ToString()); command.Parameters.AddWithValue("@dateAfter",dateTimePickerAfterTotalOutcomes.Value.ToString()); command.ExecuteNonQuery(); SQLiteDataReader da = command.ExecuteReader(); if (da.Read()){/////} } catch(Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } } 

Added SQLiteDataReader da = command.ExecuteReader (); if (da.Read ()) {/////} in da writes enumeration has not given results.

  • Judging by your code, the report will not be saved anywhere. You make a request, but do not want to receive a result from it. Look in the direction of command.ExecuteReader (), it returns the response stream. In it you will have one record with the result sum (totalSum) - pincher1519
  • @ pincher1519 and how can I get the day that is recorded in the database? - Ismoil Muhammadiev
  • one
    You need in the select body to write the name of the column with the date. Read about the sql language. After the query is executed, the DataReader will contain the result of the query. - adrug
  • one
    SELECT SUM (TotalSum), Date_Time FROM TotalOutcomes WHERE Date_Time BETWEEN @dateBefore AND @dateAfter "And as I said above, use reader to read the received data - pincher1519
  • Added SQLiteDataReader da = command.ExecuteReader (); if (da.Read ()) {/////} in da writes enumeration has not given results. - Ismoil Muhammadiyev

0