This is my code to retrive values based on an input parameter (see below)
Public Function GetAllCollectionsForParent(ByVal intParentID As Integer) As SqlDataReader
Dim strSQL As String = "SP_Name"
Dim oCon As SqlConnection
Dim oCmd As SqlCommand
Try
oCon = New SqlConnection(ConnectToDB)
oCmd = New SqlCommand(strSQL, oCon)
With oCmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@StrategyParentID", SqlDbType.Int, 4)
.Parameters("@StrategyParentID").Value = intParentID
oCon.Open()
Return .ExecuteReader(CommandBehavior.CloseConnection)
End With
Catch ex As Exception
Throw ex
End Try
End Function
The problem is that when I run the stored procedure "SP_Name" in the query analyser and pass a parameter then it returns data but when in immediate window running ?GetAllCollectionsForParent 1 then it gives this message "Invalid attempt to read when no data is present"
Any thoughts?
Thanks
Public Function GetAllCollectionsForParent(ByVal intParentID As Integer) As SqlDataReader
Dim strSQL As String = "SP_Name"
Dim oCon As SqlConnection
Dim oCmd As SqlCommand
Try
oCon = New SqlConnection(ConnectToDB)
oCmd = New SqlCommand(strSQL, oCon)
With oCmd
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@StrategyParentID", SqlDbType.Int, 4)
.Parameters("@StrategyParentID").Value = intParentID
oCon.Open()
Return .ExecuteReader(CommandBehavior.CloseConnection)
End With
Catch ex As Exception
Throw ex
End Try
End Function
The problem is that when I run the stored procedure "SP_Name" in the query analyser and pass a parameter then it returns data but when in immediate window running ?GetAllCollectionsForParent 1 then it gives this message "Invalid attempt to read when no data is present"
Any thoughts?
Thanks