executescalar() method

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

    #1

    executescalar() method

    Dear .NET Programmers,

    I use the following code snippet but can't figure out what is going wrong
    since the result object equals to nothing although it shouldn't be :)

    Function CheckMFileToBeC losed() As Boolean
    Dim result As Object
    myCommand.Param eters.Clear()
    myCommand.Comma ndText = "SELECT Result = CASE WHEN DischargeDate IS NULL
    THEN 1 " & _
    "ELSE 0 END " & _
    "FROM dbo.MedicalFoll owUpInHospital " & _
    "WHERE OurFileNo = @medicalFileNo"
    myCommand.Comma ndType = CommandType.Tex t
    myCommand.Param eters.Add("@med icalFileNo", Session("select edFileNumber")
    + "M")
    result = myCommand.Execu teScalar()
    If CInt(result) = 1 Then
    Return False
    Else
    Return True
    End If
    End Function

    Thanks in advance,

    Buran


  • Marc Hoeppner

    #2
    Re: executescalar() method

    Hi,

    my guess is that there is no row returned, therefore the result set is empty
    and the scalar result is set to NULL. The reason for not returning a row
    could be due to the WHERE OurFileNo = @medicalFileNo clause. Debug into the
    code and take a look at Session("select edFileNumber") especially the type.

    Best regards,

    Marc Höppner


    "buran" <buran@buran.co m> wrote in message
    news:%23V6lP6EU DHA.3640@tk2msf tngp13.phx.gbl. ..[color=blue]
    > Dear .NET Programmers,
    >
    > I use the following code snippet but can't figure out what is going wrong
    > since the result object equals to nothing although it shouldn't be :)
    >
    > Function CheckMFileToBeC losed() As Boolean
    > Dim result As Object
    > myCommand.Param eters.Clear()
    > myCommand.Comma ndText = "SELECT Result = CASE WHEN DischargeDate IS[/color]
    NULL[color=blue]
    > THEN 1 " & _
    > "ELSE 0 END " & _
    > "FROM dbo.MedicalFoll owUpInHospital " & _
    > "WHERE OurFileNo = @medicalFileNo"
    > myCommand.Comma ndType = CommandType.Tex t
    > myCommand.Param eters.Add("@med icalFileNo",[/color]
    Session("select edFileNumber")[color=blue]
    > + "M")
    > result = myCommand.Execu teScalar()
    > If CInt(result) = 1 Then
    > Return False
    > Else
    > Return True
    > End If
    > End Function
    >
    > Thanks in advance,
    >
    > Buran
    >
    >[/color]


    Comment

    • Cowboy \(Gregory A. Beamer\)

      #3
      Re: executescalar() method

      Only thing I see strange is the following:
      myCommand.Param eters.Add("@med icalFileNo", Session("select edFileNumber") +
      "M")

      Corrected:
      myCommand.Param eters.Add("@med icalFileNo", Session("select edFileNumber") &
      "M")

      --
      Gregory A. Beamer
      MVP; MCP: +I, SE, SD, DBA
      Author: ADO.NET and XML: ASP.NET on the Edge

      *************** *************** *************** *************** *************** *
      ****
      Think Outside the Box!
      *************** *************** *************** *************** *************** *
      ****
      "buran" <buran@buran.co m> wrote in message
      news:%23V6lP6EU DHA.3640@tk2msf tngp13.phx.gbl. ..[color=blue]
      > Dear .NET Programmers,
      >
      > I use the following code snippet but can't figure out what is going wrong
      > since the result object equals to nothing although it shouldn't be :)
      >
      > Function CheckMFileToBeC losed() As Boolean
      > Dim result As Object
      > myCommand.Param eters.Clear()
      > myCommand.Comma ndText = "SELECT Result = CASE WHEN DischargeDate IS[/color]
      NULL[color=blue]
      > THEN 1 " & _
      > "ELSE 0 END " & _
      > "FROM dbo.MedicalFoll owUpInHospital " & _
      > "WHERE OurFileNo = @medicalFileNo"
      > myCommand.Comma ndType = CommandType.Tex t
      > myCommand.Param eters.Add("@med icalFileNo",[/color]
      Session("select edFileNumber")[color=blue]
      > + "M")
      > result = myCommand.Execu teScalar()
      > If CInt(result) = 1 Then
      > Return False
      > Else
      > Return True
      > End If
      > End Function
      >
      > Thanks in advance,
      >
      > Buran
      >
      >[/color]


      Comment

      Working...