• Archives

  • Blog Stats

    • 15,963 hits
  • Jumpstart your Career and Life …

    visual basic
  • Visual Basic search

    visual basic help | visual basic download | visual basic tutorial | visual basic programming | visual basic for beginners | visual basic examples | visual basic free | Visual Basic Programming VB | learn visual basic | learn visual basic | microsoft visual basic | vb net | download visual basic | microsoft excel visual basic | Visual Basic Tutorials debugging | learn visual basic | microsoft visual basic | vb net | download visual basic | microsoft excel visual basic
  • Blog Catalog

  • Globe of Blogs

  • Blog Search

    Blog Search
  • Submit Now

  • Link with us

    Link With Us - Web Directory

Executing a Stored Procedure having INPUT and OUTPUT parameter using a Command object using Visual Basic

Executing a Stored Procedure  having INPUT and OUTPUT parameter  using a Command object

Stored procedures may contain output parameters and return values. For example, the procedure GetAccountName, can return the name of the Account for an Account Code passed as a parameter. First, create the stored procedure and then write code in the frmAccountDetails form.

Create Procedure GatAccountName
@AccCode varchar(6),
@AccName varchar(30) OUTPUT
As

SELECT  ,@AccName=AccountName FROM AccountsTable WHERE AccountCode =@AccCode
Go

The following code shows how to retrieve the output parameter from a stored procedure.

Option Explicit
Dim CN As Connection
Dim comobj As Command
Dim prmByAcc As Parameter
Dim strAcc As String

Private Sub Form_Load()
Set CN = New Connection
Set comobj = New Command

With CN
.ConnectionString = “Integrated Security=SSPI;Initial Catalog=FinAccounting;Data Source=SYS1”
.Provider = “SQLOLEDB”
.Open
End With

With comobj
.ActiveConnection = CN
.CommandText = “GetAccountName”
.CommandType = adCmdStoredProc
End With

strAcc = Trim(InputBox(“Enter Customer Code.:”))
Set prmByAcc = comobj.CreateParameter(“ACode”, adBSTR, adParamInput, 6, strAcc)
comobj.Parameters.Append prmByAcc

Set prmByAcc = comobj.CreateParameter(“AName”, adBSTR, adParamOutput, 30)
comobj.Parameters.Append prmByAcc
comobj.Execute
MsgBox comobj.Parameters(“AName”)
End Sub

Leave a Reply