< or > in my SqlDataSource's SelectCommand

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RobertTheProgrammer
    New Member
    • Aug 2007
    • 58

    < or > in my SqlDataSource's SelectCommand

    Hello,

    Hopefully this is a simple question. I'm using an ASP.NET GridView. I'm setting the SQL in my SelectCommand's SqlDataSource. I have a need to qualify a field with a "<" symbol, but ASP.NET doesn't like it because it thinks I'm trying to insert an html or ASP tag. So how does one get "<" or ">" in the query without the code interpretting it as a tag?

    Robert

    [UPDATE]
    Nevermind. I solved my own problem. Use "&lt;" and "&gt;" rather than "<" and ">". I tried to delete this thread before anyone answered, but I don't have that option. Is it only a moderator function?

    Robert
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Robert,

    Can you just post a sample of the relevant part or perhaps just a small example of what you're trying to do?

    Dr B

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      It's ok that you found the answer for yourself. the question will stay here and perhaps someone else solve their problem.
      With that in mind, perhaps you could post a little bit of code that explains what you were doing with, and the fix that you applied?

      Comment

      • RobertTheProgrammer
        New Member
        • Aug 2007
        • 58

        #4
        Okay.

        Basically, in my GridView, I am using an SqlDataSource to populate the view and the SqlDataSource had the SelectCommand set something like this (with much simplified SQL):

        START EXAMPLE:
        SelectCommand=" select field1, field2 from my table where field1 < 10"
        END EXAMPLE:

        This was failing to compile because the "<" symbol in the ASP was being interpreted as an html or ASP tag (i.e. <p>). I solved my problem by using "&lt;" instead. The code now appears like:

        START EXAMPLE:
        SelectCommand=" select field1, field2 from my table where field1 &lt; 10"
        END EXAMPLE:

        And it works as desired.

        Thanks!

        Robert
        PS. I tried using the code brackets on the above that this message board recommends ([CODE*]), but it was converting the "&lt;" symbol to "<".
        Last edited by Plater; Jun 5 '08, 05:02 PM. Reason: Note: the 2nd code uses the &lt; for the < character

        Comment

        Working...