title: Procedure returns error: Cannot cast System.Int32 to System.Int32[]
body: <p>I wrote a procedure that is supposed to return a value from my database.  The value to be returned is an integer. Here is my code:</p>
  
  <pre><code>    Private Sub btnSelectProducts_Click(sender As Object, e As EventArgs) Handles btnSelectProducts.Click
  
      Try
  
      'Connection Variables
      Dim cnn As SqlCeConnection
      Dim connectionString As String
  
      'Connect to database
      connectionString = "Data Source=|DataDirectory|\Database\ContactsAndInventory.sdf"
      cnn = New SqlCeConnection(connectionString)
  
      Dim Stream As New MemoryStream()
      cnn.Open()
  
      Dim command As New SqlCeCommand("SELECT CATEGORY_ID FROM PRODUCT_CATEGORY WHERE (CATEGORY_NAME = @CATEGORY_NAME)", cnn)
      command.Parameters.AddWithValue("@CATEGORY_NAME", txtCategoryName.Text)
  
          Dim catId As Integer() = CType(command.ExecuteScalar(), Integer())'Error Here
  
      MsgBox(catId)
  
          cnn.Close()
  
      Catch ex As Exception
  
          MsgBox(ex.ToString)
  
      End Try
  
  
  End Sub
  </code></pre>
  
  <p>I am getting the error: </p>
  
  <pre><code>System.InvalidCastException: Unable to cast objct to type System.Int32 to type System.Int32[]
  </code></pre>
  
  <p>In can't figure out why, the field is an Integer field and the value I am trying to return is an integer.  What am I doing wrong?</p>