title: Why is this function failing with "There was an error parsing the query. [Token line number, Token line offset,, Token in error,,]"?
body: <p>This code:</p>
  
  <pre><code>public bool IsValidColumn(string tableName, string columnName)
  {
      //return true;// &lt;-- when I uncomment this, I don't get the err msg (but I don't know whether it's a valid column or not, either)
      bool validColumn = false;
      string tblQuery = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tableName AND COLUMN_NAME = @columnName";
      checkConnection();
      try
      {
          SqlCeCommand cmd = objCon.CreateCommand();
          cmd.CommandText = tblQuery;
          SqlCeParameter tblNameParam = new SqlCeParameter("@tableName", SqlDbType.NVarChar, 128);
          tblNameParam.Value = tableName;
          cmd.Parameters.Add(tblNameParam);
          SqlCeParameter colNameParam = new SqlCeParameter("@columnName", SqlDbType.NVarChar, 128);
          colNameParam.Value = tableName;
          cmd.Parameters.Add(colNameParam);
          //int i = (int)cmd.ExecuteScalar();
          int i = 0;
          object obj = cmd.ExecuteScalar();
          if ((obj != null) &amp;&amp; (obj != DBNull.Value)) 
          {
              i = Int32.Parse(obj.ToString());
              validColumn = i &gt; 0;
          } 
          else 
          {
              MessageBox.Show("NULL returned from ExecuteScalar. Remove this line.");
          }
      }
      catch (SqlCeException sqlceex)
      {
          return false; 
      }
      catch (Exception ex)
      {
          return false;
      }
      return validColumn;
  }
  </code></pre>
  
  <p>...was adapted from/based on an earlier answer here: <a href="https://stackoverflow.com/questions/15693639/how-can-i-determine-whether-a-column-exists-in-a-sql-server-ce-table-with-c">How can I determine whether a column exists in a SQL Server CE table with C#?</a></p>
  
  <p>And yet, it causes me to get, "There was an error parsing the query. [Token line number, Token line offset,, Token in error,,]" (which I complained about here: <a href="https://stackoverflow.com/questions/15707487/why-is-there-an-err-parsing-this-ddl-and-why-cant-the-engine-be-more-specific">Why is there an err parsing this DDL, and why can&#39;t the engine be more specific about locating it?</a> and here: </p>
  
  <p><a href="https://stackoverflow.com/questions/15713194/sql-server-ces-ddl-parser-is-very-picky-but-secretive-about-what-it-is-finding">SQL Server CE&#39;s DDL parser is very picky but secretive about what it is finding fault with</a>).</p>
  
  <p>In my attempts to get to the bottom of what was causing this err msg, I've actually refactored the legacy code a fair amount (threw a lot of rancid spaghetti out of the fridge), so it hasn't been a waste of time, but now I find that what was causing that err msg was something in the code above. So the question is: How <em>can</em> I determine whether a column is valid without generating this err msg?</p>