title: How to compare(less than or equal to) two sql columns in C# from code behind file
body: <p>I am stuck at comparing a combobox value with a SQL Column. I am trying to do it from VS 2010 with C#. I am using SQL Server 2008.</p>
  
  <p>Please find below, my SQL table. </p>
  
  <pre><code>Rings  NR     Name  Dia
  =======================
  10     12     a     15  
  10     24     b     18  
  10     15     c     21  
  10     9      d     24  
  10     7      e     15  
  10     19     f     18  
  10     33     g     24  
  10     36     h     13  
  </code></pre>
  
  <p>What I am trying to compare values of <code>Rings</code> column and <code>NR</code> column. </p>
  
  <p>My SQL query is this.</p>
  
  <pre><code>select * from tblData  where Dia=15 and (Rings&lt;=NR)
  </code></pre>
  
  <p>I am able to run this query successfully in SQL and get the desired results but I am stuck to achieve this in C#. How can I compare two columns in C#?</p>
  
  <p>My C# code is:</p>
  
  <pre><code> string connectionString = ConfigurationManager.ConnectionStrings["QuoteProjectConnectionString"].ConnectionString;
   using (SqlConnection connection = new SqlConnection(connectionString))
   using (SqlCommand command = connection.CreateCommand())
   {
       {
           try
           {
              int a = Convert.ToInt32(cmbbx.SelectedItem.Text);
              command.CommandText = "Update tblData set Rings= " + 
                                       cmbbxRings.SelectedItem.Text+" ";
              connection.Open();
              command.ExecuteNonQuery(); 
              command.CommandText = "(select * from tblData where Dia=" + 15 +
                                       " and NR="+(a)&lt;="NR"")";
              command.ExecuteNonQuery(); 
           }
           catch (SqlException ex)
           {
           }
  </code></pre>
  
  <p>I am struggling to write this part of the query in C#: </p>
  
  <pre><code> (NR="+(a)&lt;="NR) 
  </code></pre>