Why does this code not work???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kelly E

    #1

    Why does this code not work???

    Here's my function. I keep getting 'Object not set to an
    instance of an object when I call myDR.Read. (I'm using
    the Application Data blocks v1). I have similar routines
    throughout this project that work - I don't see any code
    differences. Any suggestions???

    Private Function GetOrderSession Id(ByVal OrderId As
    Integer) As String

    Dim myDR As SqlDataReader
    myDR = SqlHelper.Execu teReader
    (ConfigurationS ettings.AppSett ings("connectio nString"), _
    CommandType.Tex t, "Select SessionId from
    Orders where OrderId = " & OrderId)

    If myDR.Read = True Then 'ERROR HERE
    Return myDR("SessionId ")
    End If
    myDR.Close()

    End Function
  • solex

    #2
    Re: Why does this code not work???

    What is SQLHelper? Your errro probably orginates there.


    "Kelly E" <anonymous@disc ussions.microso ft.com> wrote in message
    news:143e801c3c 32b$80565f20$a6 01280a@phx.gbl. ..[color=blue]
    > Here's my function. I keep getting 'Object not set to an
    > instance of an object when I call myDR.Read. (I'm using
    > the Application Data blocks v1). I have similar routines
    > throughout this project that work - I don't see any code
    > differences. Any suggestions???
    >
    > Private Function GetOrderSession Id(ByVal OrderId As
    > Integer) As String
    >
    > Dim myDR As SqlDataReader
    > myDR = SqlHelper.Execu teReader
    > (ConfigurationS ettings.AppSett ings("connectio nString"), _
    > CommandType.Tex t, "Select SessionId from
    > Orders where OrderId = " & OrderId)
    >
    > If myDR.Read = True Then 'ERROR HERE
    > Return myDR("SessionId ")
    > End If
    > myDR.Close()
    >
    > End Function[/color]


    Comment

    • Kelly E

      #3
      Re: Why does this code not work???

      SqlHelper is the MS Application Block object. The
      application blocks are classes MS built to make our lives
      easier in writing data access code. I use the object
      everywhere in this project.
      [color=blue]
      >-----Original Message-----
      >What is SQLHelper? Your errro probably orginates there.
      >
      >
      >"Kelly E" <anonymous@disc ussions.microso ft.com> wrote in[/color]
      message[color=blue]
      >news:143e801c3 c32b$80565f20$a 601280a@phx.gbl ...[color=green]
      >> Here's my function. I keep getting 'Object not set to[/color][/color]
      an[color=blue][color=green]
      >> instance of an object when I call myDR.Read. (I'm[/color][/color]
      using[color=blue][color=green]
      >> the Application Data blocks v1). I have similar[/color][/color]
      routines[color=blue][color=green]
      >> throughout this project that work - I don't see any[/color][/color]
      code[color=blue][color=green]
      >> differences. Any suggestions???
      >>
      >> Private Function GetOrderSession Id(ByVal OrderId As
      >> Integer) As String
      >>
      >> Dim myDR As SqlDataReader
      >> myDR = SqlHelper.Execu teReader
      >> (ConfigurationS ettings.AppSett ings[/color][/color]
      ("connectionStr ing"), _[color=blue][color=green]
      >> CommandType.Tex t, "Select SessionId from
      >> Orders where OrderId = " & OrderId)
      >>
      >> If myDR.Read = True Then 'ERROR HERE
      >> Return myDR("SessionId ")
      >> End If
      >> myDR.Close()
      >>
      >> End Function[/color]
      >
      >
      >.
      >[/color]

      Comment

      • Chris Dunaway

        #4
        Re: Why does this code not work???

        On Mon, 15 Dec 2003 08:50:10 -0800, Kelly E wrote:
        [color=blue]
        > Any suggestions???[/color]

        Try running the SQL query in Query Analyzer. It's possible that the query
        does not return anything, so the myDR datareader is null.
        [color=blue]
        > Dim myDR As SqlDataReader
        > myDR = SqlHelper.Execu teReader
        > (ConfigurationS ettings.AppSett ings("connectio nString"), _
        > CommandType.Tex t, "Select SessionId from
        > Orders where OrderId = " & OrderId)
        >[/color]

        If you put a break point at the line above and then step through it, is the
        myDR variable Nothing? Again, it sounds like your SQL query is not return
        anything. Is the OrderId valid and are there items in the Orders table for
        that OrderId?

        Just some thoughts

        --
        Chris

        To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
        address.

        Comment

        • solex

          #5
          Re: Why does this code not work???

          Kelly,

          What namespace does the SQLHelper reside, I could not find it in the help?
          I use a similar pattern for returning a row or rows of data and do not have
          a problem (shown below). As I suggested before the error must reside in
          some where in/around SQLHelper because the reader is not properly
          instantiated, (perhaps the connect string is incorrect).

          Even if your query does not return rows the Reader.Read method should return
          a value.

          Dan

          If rdr.Read() Then
          ...
          End If

          While rdr.Read
          ...
          End While


          "Kelly E" <anonymous@disc ussions.microso ft.com> wrote in message
          news:078e01c3c3 32$21296d10$a00 1280a@phx.gbl.. .[color=blue]
          > SqlHelper is the MS Application Block object. The
          > application blocks are classes MS built to make our lives
          > easier in writing data access code. I use the object
          > everywhere in this project.
          >[color=green]
          > >-----Original Message-----
          > >What is SQLHelper? Your errro probably orginates there.
          > >
          > >
          > >"Kelly E" <anonymous@disc ussions.microso ft.com> wrote in[/color]
          > message[color=green]
          > >news:143e801c3 c32b$80565f20$a 601280a@phx.gbl ...[color=darkred]
          > >> Here's my function. I keep getting 'Object not set to[/color][/color]
          > an[color=green][color=darkred]
          > >> instance of an object when I call myDR.Read. (I'm[/color][/color]
          > using[color=green][color=darkred]
          > >> the Application Data blocks v1). I have similar[/color][/color]
          > routines[color=green][color=darkred]
          > >> throughout this project that work - I don't see any[/color][/color]
          > code[color=green][color=darkred]
          > >> differences. Any suggestions???
          > >>
          > >> Private Function GetOrderSession Id(ByVal OrderId As
          > >> Integer) As String
          > >>
          > >> Dim myDR As SqlDataReader
          > >> myDR = SqlHelper.Execu teReader
          > >> (ConfigurationS ettings.AppSett ings[/color][/color]
          > ("connectionStr ing"), _[color=green][color=darkred]
          > >> CommandType.Tex t, "Select SessionId from
          > >> Orders where OrderId = " & OrderId)
          > >>
          > >> If myDR.Read = True Then 'ERROR HERE
          > >> Return myDR("SessionId ")
          > >> End If
          > >> myDR.Close()
          > >>
          > >> End Function[/color]
          > >
          > >
          > >.
          > >[/color][/color]


          Comment

          Working...