title: System.Data.SqlClient.SqlException: Invalid column name
body: <p>Trying to do a recordset, I just want one column of data, but this code is giving me an error.. I'm an ASP.NET newb, can anyone help?:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlException: Invalid column name
    'CustomerName'.</p>
  </blockquote>
  
  <pre><code> using (SqlConnection con = new SqlConnection(DB.GetDBConn()))
   {
    con.Open();
    using (IDataReader dr = DB.GetRS("select CustomerName from Customer where CustomerID=" + Customer.CustomerID, con))
     {
         string CustomerName = "CustomerName";                    
     }
   }
  
   String EncCustomerName = Encrypt(CustomerName.Replace(".", "").Replace("-", ""),"1");
  </code></pre>
  
  <p>Question #2:  How do I bind the database content to the CustomerName string? It seems like its only returning "CustomerName" as the value for CustomerName string.. I would like it to return the database data for CustomerName string..  Help?</p>
  
  <p>Suggested to use a ExecuteScalar, so i modified the request to this </p>
  
  <pre><code>   using (var con = new SqlConnection(DB.GetDBConn()))
     using (var cmdContrib = new SqlCommand("SELECT CustomerName FROM Customer WHERE   CustomerID=" + ThisCustomer.CustomerID, con))
  
     {
  
          con.Open();
          string CustomerName = cmdContrib.ExecuteScalar();
     } 
  </code></pre>
  
  <p>And i Get this error:
  "string CustomerName = cmdCust.ExecuteScalar();"</p>
  
  <p>CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)</p>