iscivanomar
asked on
How to execute a SQL Server 2005 Stored Procedure and get a return value in VB6?
Hello everyone,
I have an application in Visual Basic 6 and I need to execute a stored procedure and get a return value. How can I do this? what is the code that I can use.
Visual Basic 6 no Visual Basic.NET
Thank you
I have an application in Visual Basic 6 and I need to execute a stored procedure and get a return value. How can I do this? what is the code that I can use.
Visual Basic 6 no Visual Basic.NET
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Looks like @AielloJ missed the
Visual Basic 6 no Visual Basic.NET
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your help,
It's been awhile, but this should work for you:
CREATE PROCEDURE my_proc
@param1 varchar(10),
@param2 int
:
:
:
:
Public Shared Function my_function(ByVal myVB_Param As String) As String
'create connection
Using cnSQL As SqlConnection = New SqlConnection("MyConnectio
Using cmdSP As New SqlCommand("my_proc", cnSQL)
cmdSP.CommandType = System.Data.CommandType.St
'declare and add parameter
cmdSP.Parameters.Add("@par
cmdSP.Parameters.Add("@par
Dim dtTable As New DataTable
'execute command
Try
cnSQL.Open()
dtTable.Load(cmdSP.Execute
cnSQL.Close()
Catch ex As SqlException
'do something here
End Try
'return string
Return dtTable.Rows(0)(0)
End Using
End Using
End Function
Best regards,
AielloJ