title: Retrieve Data from SQL Server based on TextBox value in C#
body: <p>I have a database with 4 columns <code>HouseNo</code>, <code>Date</code>, <code>Time</code> and <code>IndoorTemp</code>. In my C# Windows application I have 4 textboxes, one each for the above columns.</p>
  
  <p>The user enters the HouseNo, Date and Time values in the Text Box. The inputs here should be a part of my SQL Where Clause with the output as the Indoor Temperature. This should then be displayed in the last text box.</p>
  
  <p>I have used this connection:</p>
  
  <pre><code>    // Create a String to hold the database connection string.
      string sdwConnectionString = @"Data Source=IE1ADTBD5ZL1S\;Initial Catalog=ThermostatData2;Integrated Security=True";
  
      // Create a connection
      SqlConnection sdwDBConnection = new SqlConnection(sdwConnectionString);
  </code></pre>
  
  <p>I tried a code to do this but it failed. 
  My code is,</p>
  
  <pre><code>cmd.IndoorTemp = "select * from ThermData where HouseNo = '" + HouseNovalue.Text + "' and Date = '" + Datevalue.Text + "' and Time = '" + Timevalue.Text + "' ";
  </code></pre>
  
  <p>How do i achieve the desired result. </p>
  
  <p>I am new to C# and do not know much. All the above code was also with the help of a few blogs. </p>
  
  <p>Do please help me out on this one. Also suggest a good book where i could learn to program C# with SQL Server. Thanks a lot in advance.</p>