SQL query with datareader or dataadapter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaveRook
    New Member
    • Jul 2007
    • 147

    #1

    SQL query with datareader or dataadapter

    Hello

    One of my colleagues has done this in vbscript. His code within the recordset is

    Code:
    "SELECT DISTINCT (ProductNumber), NoOfContacts, Height, Style, Type FROM view WHERE ProfileHeight between 3.0 and 3.9"
    How can he be calling the column ProfileHeight when it is not declared?

    I am trying to do this in C#, and I can't - if it goes to the dataapater it fails because it wants the column ProfileHeight to be declared.

    Any ideas?
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Dave,

    Try asking the first questions first - does his code actually work?

    Assume it does. Then the next question is if you and he are looking at the same "view".

    If not, sort that out.

    If, however, the view is the same, then I'm as confused as you are.

    Luck!

    Comment

    • DaveRook
      New Member
      • Jul 2007
      • 147

      #3
      Hello

      His code works perectly.

      The view and my view are pretty much the same (different data) but the actual set up is identical.

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        Dave,

        It sounds like his view has a ProfileHeight field, where yours doesn't.

        Is there any way you can do something like "SELECT * FROM view" on his system and see what fields are actually there?

        Comment

        • DaveRook
          New Member
          • Jul 2007
          • 147

          #5
          Hi

          Had another look.

          It appears when you build a recordset or dataadapter, the where clause ignores what columns appear in your select command and looks at the columns available on the actual view on SQL.

          I've managed to replicate this now with my C# code and it is fine.

          Thank you

          Comment

          • Oralloy
            Recognized Expert Contributor
            • Jun 2010
            • 988

            #6
            Good on you, and good luck with your assignment.

            Comment

            Working...