SQLReader and Stored Procedure No results shows rdr as having rows????

R

Roger

I have a stored procedure I am calling to return resuts if there any to a
sqldatareader.

The problem I am having is my code thinks it is always returning results...

the While rdr2.read always passes and the rdr2.has rows is true even
if the stored procdure returns no results.

I have tested this by runing the stored procedure manually and it shows NO
results.

What could be my problem? Here is my simple code and stored procedure....

Thanks,


******* Code


Dim cmd As New SqlClient.SqlCommand("R_GetSiphoned")
Dim rdr2 As SqlClient.SqlDataReader
cmd.Connection = cn
If cmd.Connection.State = ConnectionState.Closed Then
cmd.Connection.Open()
End If
cmd.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
cmd.Parameters.Add("@Siteid", CStr(dtnew.Rows(i).Item(0)))
cmd.Parameters.Add("@Date", CDate("1/1/2010"))
rdr2 = sqlCmd.ExecuteReader()
While rdr2.Read
If rdr2.HasRows Then
dtnew.Rows(i).Item(j + 1) = "X"
Else
dtnew.Rows(i).Item(j + 1) = "O"
End If
End While


**************

Stored Procedure.....

ALTER PROCEDURE R_GetSiphoned

@SiteID varchar(10),
@Date datetime

AS
SELECT CONVERT(varchar(10), siphonTransferAt, 101) AS Expr1, siteID
FROM a_siphon
WHERE siteID = @SiteID AND (CONVERT(varchar(10), siphonTransferAt, 101)
= @date)
return
 
W

William \(Bill\) Vaughn

See http://www.betav.com/msdn_magazine.htm and my article on handling
parameters from stored procedures.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

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

Top