Forums - C# Corner

Forum guidelines
Abdalla Omran

Abdalla Omran

  • 1.7k
  • 85
  • 796

How to read several different commands in one method

Jun 24 2019 7:46 AM
Hallo
 
i want to read many different commands in one method passing int year as parameter for method . the method should read 3 different commands for example 2017,2018 and 2019 .
what i have done so far is the following
 
What I have tried:
  1. public int GetSumYear(int year)  
  2. {  
  3. int sum = 0;  
  4. string CS = "+++++"  
  5. using (SqlConnection connection = new SqlConnection(CS))  
  6. {  
  7. connection.Open();  
  8. SqlCommand command = new SqlCommand("select COUNT (ÜbertragenAm) from BranchSale_all where ÜbertragenAm between '2017-01-01' and '2018-01-01'", connection);  
  9. // here i want to read the same command for 2018 and 2019  
  10. sum = (int)command.ExecuteScalar();  
  11. }  
  12. return sum;  
  13. }  

Answers (2)