executescalar() method

B

buran

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 CheckMFileToBeClosed() As Boolean
Dim result As Object
myCommand.Parameters.Clear()
myCommand.CommandText = "SELECT Result = CASE WHEN DischargeDate IS NULL
THEN 1 " & _
"ELSE 0 END " & _
"FROM dbo.MedicalFollowUpInHospital " & _
"WHERE OurFileNo = @medicalFileNo"
myCommand.CommandType = CommandType.Text
myCommand.Parameters.Add("@medicalFileNo", Session("selectedFileNumber")
+ "M")
result = myCommand.ExecuteScalar()
If CInt(result) = 1 Then
Return False
Else
Return True
End If
End Function

Thanks in advance,

Buran
 
M

Marc Hoeppner

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("selectedFileNumber") especially the type.

Best regards,

Marc Höppner
 
C

Cowboy \(Gregory A. Beamer\)

Only thing I see strange is the following:
myCommand.Parameters.Add("@medicalFileNo", Session("selectedFileNumber") +
"M")

Corrected:
myCommand.Parameters.Add("@medicalFileNo", Session("selectedFileNumber") &
"M")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top