title: Pass parameters correctly to SqlCommand
body: <p>I have code to insert data to SQL table.
  The columns have such types:</p>
  
  <pre><code>@param1 datetime,
  @param2 nvarchar(50),
  @param3 int,
  @param4 bit,
  @param5 int,
  @param6 bit,
  @param7 bit,
  @param8 varchar(20),
  @param9 varchar(20)
  </code></pre>
  
  <p>This is my method:</p>
  
  <pre><code>try
  {
      using (SqlCommand oleDbCommand = new SqlCommand())
      {
          // Set the command object properties
          oleDbCommand.Connection = new SqlConnection(connectionString);
          oleDbCommand.CommandType = CommandType.StoredProcedure;
          oleDbCommand.CommandText = "[dbo].[InsertRow]";
          // Add the input parameters to the parameter collection
          // m.param1 is of DateTime type, m.param2 of string type, m.param3 of int type, etc.
          oleDbCommand.Parameters.AddWithValue("@param1", m.param1);
          oleDbCommand.Parameters.AddWithValue("@param2", m.param2);
          oleDbCommand.Parameters.AddWithValue("@param3", m.param3);
          oleDbCommand.Parameters.AddWithValue("@param4", m.param4);
          oleDbCommand.Parameters.AddWithValue("@param5", m.param5);
          oleDbCommand.Parameters.AddWithValue("@param6", m.param6);
          oleDbCommand.Parameters.AddWithValue("@param7", m.param7);
          oleDbCommand.Parameters.AddWithValue("@param8", m.param8);
          oleDbCommand.Parameters.AddWithValue("@param9", m.param9);
          // Open the connection, execute the query and close the connection.
          oleDbCommand.Connection.Open();
          oleDbCommand.ExecuteNonQuery();
          oleDbCommand.Connection.Close();
      }
  }
  catch (Exception ex)
  {
      MessageBox.Show(ex.Message);
      return false;
  }
  </code></pre>
  
  <p>I have two but related questions:</p>
  
  <ul>
  <li>am I passing parameters correctly? Or do I need casts? (please see the column types in the
  beginning of the question).</li>
  <li>how to correctly handle closing of database? In case also of some exception?</li>
  </ul>