Declan Basile
asked on
Opening an ADO Recordset from a SQL Server Stored Procedure using VB.NET
The posted code in VB.net doesn't display a MsgBox. Typing "EXEC procUserOperations 154" from a query windows in SQL Server works. The VB.net program doesn't output an error or "bomb out". It just continues on with its execution. I can even purposefully type a stored procedure name that doesn't exist for the CommandText and the program still doesn't "bomb out" or give an error message. What's wrong with this code, and how can I debug this program? The stored procedure returns a recordset and its declaration is :
ALTER PROCEDURE [dbo].[procUserOperations]
@ParentOperationId As Int
As
BEGIN
ALTER PROCEDURE [dbo].[procUserOperations]
@ParentOperationId As Int
As
BEGIN
Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim Param As New ADODB.Parameter
Dim rs As New ADODB.Recordset
cn.ConnectionString = strConn2
cn.Open()
With cmd
.CommandText = "procUserOperations"
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.ActiveConnection = cn
Param = .CreateParameter("ParentOperationId", ADODB.DataTypeEnum.adInteger,
ADODB.ParameterDirectionEnum.adParamInput,, 154)
.Parameters.Append(Param)
rs = .Execute
End With
MsgBox(rs.Fields("UserId").Value & "1")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I ended up converting the code to use SQLDataReader.
MessageBox.Show( "The username or password you entered is incorrect", _
"Login Error", MessageBoxButtons.OKCancel