title: Specified cast is not valid when trying Convert.ToInt32(value)
body: <p>I am trying to run a stored procedure and for some reason it keeps telling me <code>"Specified cast is not valid"</code>. the "<code>hidSelectedExpenseIDs</code>" is a hidden field that gets populated with a javascript array of id's. </p>
  
  <p>Example: the <code>"hidSelectedExpenseIDs.Value"</code> would look like "123,124,125,126". Hence why I have the <code>.Split(',')</code> in there.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void hasExhistingExpenseInvoice()
  {
      string[] Expenses = hidSelectedExpenseIDs.Value.Split(',');
  
      //check if there is an existing invoice. Then report back to the user so the
      //user knows if he/she has to check overwrite option.
      bool invoiceExists = false;
  
      foreach (var expense in Expenses)
      {
          var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
          var command = new SqlCommand("p_CaseFiles_Expenses_InvoiceExhists", connection);
          command.Parameters.Add(new SqlParameter("@ExpenseID", SqlDbType.Int));
          command.Parameters["@ExpenseID"].Value = Convert.ToInt32(expense);
          command.CommandType = CommandType.StoredProcedure;
          try
          {
              connection.Open();
              invoiceExists = (bool)command.ExecuteScalar();
              if (invoiceExists)
              {
                  //previous invoice exhists
                  Warning1.Visible = true;
                  Warning1.Text = "There is an exhisting Invoice.";
              }
          }
          catch (SqlException sql)
          {
              lblStatus.Text = "Couldn't connect to the Database - Error";
              lblStatus.ForeColor = System.Drawing.Color.Red;
          }
          catch (Exception ex)//catches exception here
          {
              lblStatus.Text = "An error occured";
              lblStatus.ForeColor = System.Drawing.Color.Red;
          }
          finally
          {
              if (connection.State == ConnectionState.Open)
                  connection.Close();
          }
      }
  }
  </code></pre>
  
  <p>this is my stored procedure:</p>
  
  <pre><code>ALTER PROCEDURE dbo.[InvoiceExhists]
  @ExpenseID int
  AS
  BEGIN
      SELECT InvNumber FROM dbo.Expenses from ExpID = @ExpenseID
  END
  </code></pre>