title: SQL CE 3.5 - Writing to a database
body: <p>I'm trying to write to a data base, I have been working of the <a href="http://arcanecode.com/2007/04/13/sql-server-compact-edition-with-c-and-vbnet/" rel="nofollow noreferrer">following site</a>. In particular the <code>LoadARow</code> function. </p>
  
  <p>I have been getting the runtime error </p>
  
  <blockquote>
    <p>"System.IndexOutOfRangeException: A SqlCeParameter with ParameterName 'Value' is not contained by this SqlCeParamaterCollection. </p>
  </blockquote>
  
  <p>The error references the line "command.Parameters["@Value"].Value = num;". The database I'm using has a Value column set as the key, and a text column.</p>
  
  <pre><code>using (SqlCeConnection connect = new SqlCeConnection("Data Source=C:\\Users\\mike\\Documents\\database.sdf"))
  {
    connect.Open();
  
    string text = "test";
    int num = 0;
  
    using (SqlCeCommand command = new SqlCeCommand("insert into Data Table values (@Value, @Text)", connect))
    {
      command.Parameters.Add("@Text", SqlDbType.NVarChar);
      command.Parameters["@Value"].Value = num;
      command.Parameters.AddWithValue("@Text", text);
      command.ExecuteNonQuery();
    }
  }
  </code></pre>