Link to home
Start Free TrialLog in
Avatar of Declan Basile
Declan BasileFlag for United States of America

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

       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")

Open in new window

Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Try this ..

MessageBox.Show( "The username or password you entered is incorrect", _
        "Login Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop)
ASKER CERTIFIED SOLUTION
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Declan Basile

ASKER

Thanks.  I ended up converting the code to use SQLDataReader.