in MS ACCESS Request

SELECT SalesByTYPE.TYPE, SalesByTYPE.KILK, SalesByTYPE.WART FROM SalesByTYPE;

returns such a set:

TYPE KILK WART

LD 4000 3000

HD 2000 7000

I want to get the same in C #, my code

 private static string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=tgdb.accdb;Jet OLEDB:Database Password = pwd;"; using (OleDbConnection conn = new OleDbConnection(connString)) { conn.Open(); SQL = "SELECT * FROM SalesByTYPE"; using (OleDbCommand comm = new OleDbCommand(SQL, conn)) { using (OleDbDataReader reader = comm.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { answer += $"{reader[0]} :\t{reader[1]} ,\t{reader[2]} .\n"; } Console.WriteLine(answer); } else // { answer = $"Error During Getting The Database Answer"; Console.WriteLine(answer); } } } } 

As a result of code execution I get:

LD 6000 10,000

those. the first cell of the first row and the total values ​​of the columns. But why and how to fix it?

  • So the columns do not correspond to the order SalesByTYPE.TYPE, SalesByTYPE.KILK, SalesByTYPE.WART - Artem Okonechnikov
  • In any incomprehensible situation, run the debugger and see the intermediate values. - Gennady P
  • @ArtyomOkonechnikov how exactly do not correspond? because the SELECT * FROM SalesByTYPE does not take into account the order - Aleksandr H.
  • @ GennadyP what to watch in debagger? The While loop runs once, although it must pass 2 times - Aleksandr H.
  • See the SalesByTYPE table for its columns. If you push your query above into the code (the one that ...SalesByTYPE.TYPE, SalesByTYPE.KILK, SalesByTYPE.WART... ), then everything works correctly? - Artyom Okonechnikov

0