473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 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
Nov 17 '05 #1
2 10450
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
"buran" <bu***@buran.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #2
Only thing I see strange is the following:
myCommand.Parameters.Add("@medicalFileNo", Session("selectedFileNumber") +
"M")

Corrected:
myCommand.Parameters.Add("@medicalFileNo", Session("selectedFileNumber") &
"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" <bu***@buran.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WeiminZhang | last post by:
When I use the OleDb to connect a Oracle db, and use the ExecutScalar() method to get the count of a table, the return value can't be cast to a data type, say int, while this works fine for a SQL...
3
by: AL | last post by:
Hello. I've been programming in C# for about 6 months, and I have a question; I was experimenting with some code this evening, for example this; this.sqlConnection1.Open(); int qty = (int)...
2
by: Dinesh | last post by:
Hi, I have one stored procedure in SQL server in which i have written one insert statement. Now in my cs file i pass the parameters require to execute that stored procedure and finaly by mistaken...
2
by: Mike Krajewski | last post by:
We are having an intermittent problem using an ExecuteScalar command on a asp.NET page accessing SQL Server. 2 characters of the sql statement get intermittently altered. The code looks as...
5
by: bienwell | last post by:
Hi all, I have a problem with using myCommand.ExecuteScalar(). My question is : If the Web setup is incorrect, does it make command ExecuteScalar() work improperly ?? In my program, I was...
3
by: charliewest | last post by:
Hi - I need to detect when the ExecuteScalar() method of the cmd object returns NULL. I have tried the below code, however, it always returns false (this is to say, that ExecuteScalar never...
9
by: eagle | last post by:
How can I return the new id that is created when an insert command is used? for example: qry = "insert into tblClients (lname, fname) values ('smith', 'joe')" Dim xyz as string =...
2
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL...
2
by: Manikandan | last post by:
Hi, I have a table with following data Tablename:details No(varchar) Name(varchar) Updated(Datetime) 1 mm 10/10/2006 2 nn 02/12/2005 3 kk NULL I'm using executescalar to get the...
1
by: Manikandan | last post by:
Hi, I have a table with following data Tablename:details No(varchar) Name(varchar) Updated(Datetime) 1 mm 10/10/2006 2 nn 02/12/2005 3 kk NULL I'm using executescalar to get the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.