calculating the average of field entries
<p>I am trying to calculate the average of some int entries in a database table using a basic ado.net procedure but get an error that states that the cast is not valid.</p>

<pre><code>try
        {
            int average;

            string conn = @"Provider=Microsoft.Jet.OleDb.4.0;
                                               Data Source=BookRateInitial.mdb";
            OleDbConnection connection = new OleDbConnection(conn);



            OleDbCommand cmd = connection.CreateCommand();

            cmd.CommandText = @"SELECT AVG(rating) FROM bookRated WHERE title = 'the informers'";

            connection.Open();
            average = (int)cmd.ExecuteScalar();

            Console.WriteLine("The average is thus {0}", average);
            connection.Close();

        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
      }
</code></pre>

<p>Is this the correct way of calculating the average of a set of entries in a database?.</p>

<p>Kind regards</p>
