title: Retrieve output parameter of SQL statement
body: <p>I'm using a table with two columns, <code>customer_id</code> and <code>customer_name</code>.</p>
  
  <p><code>customer_name</code> is a simple <code>varchar</code>, <code>customer_id</code> is an auto incrementing primary key.</p>
  
  <p>I want to use my C# application to insert a <code>customer_name</code>, and retrieve the value of the <code>customer_id</code>.</p>
  
  <p>Just inserting is simply solved by using </p>
  
  <pre><code>using (SqlConnection connection = new SqlConnection(AppConstants.ConnectionString))
  {
      using (SqlCommand command = new SqlCommand("INSERT INTO custom_customer (customer_name) VALUES (@name);"))
      {
          command.Parameters.Add(new SqlParameter("name", customer));
          connection.Open();
          command.ExecuteNonQuery();
          connection.Close();
      }
  }
  </code></pre>
  
  <p>I found some documentation of the <code>OUTPUT</code> statement, which can be used to retrieve a value.</p>
  
  <p>I think the correct syntax would be </p>
  
  <pre><code>INSERT INTO custom_customer (customer_name) 
  OUTPUT Inserted.customer_id 
  VALUES (@name);
  </code></pre>
  
  <p>And I figure I need to use</p>
  
  <pre><code>command.ExecuteReader();
  </code></pre>
  
  <p>But then I'm stuck. How should I go about getting the value from the query? </p>