Hello.
I'm pretty new to VB.NET, and I'm trying to get my .NET code to execute a SQL Server stored procedure and return the recordset. The stored procedure is executing, but no rows are returned into the DataReader as indicated by my message box. Can anyone tell me what I'm missing? Thanks.
Tracey
I'm pretty new to VB.NET, and I'm trying to get my .NET code to execute a SQL Server stored procedure and return the recordset. The stored procedure is executing, but no rows are returned into the DataReader as indicated by my message box. Can anyone tell me what I'm missing? Thanks.
Tracey
Code:
'Connection - Declare and open connection
Dim myConnectionString As String = "Integrated Security=XXXX;Persist Security Info=False;Initial Catalog=DataBaseName;Data Source=ServerName;Packet Size=XXXX"
Dim myConnection As SqlConnection = New SqlConnection(myConnectionString)
myConnection.Open()
'Command
Dim mySqlCommand As SqlCommand = New SqlCommand("sp_myStoredProcedure", myConnection)
'DataReader - Declare DataReader and populate with result set from stored procedure.
Dim myReader As SqlDataReader = mySqlCommand.ExecuteReader()
Try
'If myReader.HasRows Then
If myReader.Read <> False Then
Do While myReader.Read()
MsgBox("Rows Returned.", MsgBoxStyle.Information)
Loop
Else
MsgBox("No rows returned.", MsgBoxStyle.Information)
End If
Finally
myReader.Close()
myConnection.Close()
End Try