title: Store value in a variable after using select statement
body: <p>How to store the value of the <code>PolicyID</code> returned from database in an integer variable in <code>C#</code>?</p>
  
  <p>I am using SQL server 2005.</p>
  
  <pre><code>        System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
          dataConnection.ConnectionString =
              @"Data Source=JAGMIT-PC\SQLEXPRESS;Initial Catalog=SumooHAgentDB;Integrated Security=True";
  
          System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
          dataCommand.Connection = dataConnection;
          dataCommand.CommandText = ("select PolicyID from Policies where PolicyID=(select max(PolicyID) from Policies)");
  
  
  
          dataConnection.Open();
          dataCommand.ExecuteNonQuery();
          dataConnection.Close();
  </code></pre>
  
  <p>Please suggest.</p>
  
  <p>Thanks.</p>