title: How to create sql connection with c# code behind, access the sql server then conditionally redirect?
body: <p>This is a question from an experienced beginner!</p>
  
  <p>Using ASP.NET 4 C# AND SQL server,</p>
  
  <p>I have a connection string in web.config to myDatabase named "myCS".
  I have a database named myDB.
  I have a table named myTable with a primary key named myPK</p>
  
  <p>What are the NECESSARY lines of code behind (minimal code) to create a SQL connection, then select from myTable where myPK=="simpleText"</p>
  
  <p>it will probably include:</p>
  
  <pre><code>sqlconnection conn = new sqlconnection(??? myCS)
  string SQLcommand = select * from myDB.myTable where myPK==myTestString;
  sqlCommand command = new SqlCommand(SQL,conn);
  
  conn.Open();
  
  booleanFlag = ????
  
  conn.Close();
  conn.Dispose();
  </code></pre>
  
  <p>then</p>
  
  <pre><code>If ( theAnswer  != NULL )  // or (if flag)
  {
  Response.Redirect("Page1.aspx");
  }
  else
  {
  Response.Redirect("Page2.aspx");
  }
  </code></pre>