How to get a number ( int ) obtained as a result of such a SQL query:

 SELECT id FROM table1 WHERE name="name" 

It turns out to output only with the use of foreach , which is very cumbersome:

 SQLiteDataReader reader = command.ExecuteReader(); foreach (DbDataRecord item in reader) { intvalue = Convert.ToInt32(item["id"]); } 

This is probably more correct, because the MAX function is working.

  • 2
    And what is bulky in foreach , whose body consists of a single line? - Regent
  • To be honest, I thought that it was possible to somehow turn directly to the reader - Leonid

1 answer 1

 using(SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { intvalue = Convert.ToInt32(reader["id"]); } }