title: DBnull to integer conversion error
body: <p>I get the <code>Conversion from type 'DBNull' to type 'Integer' is not valid." error on the line "Dim avgObject As string = Cstr(avgCom.ExecuteScalar())</code></p>
  
  <p>The command works when the <code>where module_ID='" &amp; moduleSelect &amp; "'</code> statement is removed and I do not know how to fix this, can anyone help?</p>
  
  <pre><code>    Dim moduleSelect As String = moduleRadio.SelectedValue
      Using connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
          Using avgCom As New SqlCommand("SELECT AVG(exam) FROM completed_module where module_ID='" &amp; moduleSelect &amp; "' ", _
                                          connection)
              connection.Open()
              Dim avgObject As Integer = CInt(avgCom.ExecuteScalar())
              Dim averageVar As String
              averageVar = avgObject.ToString
              avgLabel.Text = averageVar
          End Using
  </code></pre>