Hi
I have the below code for executing stored procedures and retreviing the returned value.
It works perfectly to execute procedures with no parameters, but as soon as I add parameters it errors with:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Any help would be much appreciated, I have tried many types of example code from google with no luck.
Thanks
B
'Calling Code
MsgBox(SQLDataProvider_SP.execute_SP_ReturnParam(strConnectionString, "dbo.sp_mytestprocedure", "DBNAME"))
'Function
Public Shared Function execute_SP_ReturnParam(ByVal strConString As String, ByVal strSPName As String, ByVal strDBName As String)
Dim objCN As SqlConnection = New SqlConnection(strConString)
Dim objCommand As SqlCommand = New SqlCommand(strSPName, objCN)
objCommand.CommandTimeout = 20
objCommand.CommandType = CommandType.StoredProcedure
Dim inputValue As New SqlParameter("@iReturn", SqlDbType.Int)
inputValue.Direction = ParameterDirection.Output
objCommand.Parameters.Add(inputValue)
objCN.Open()
Dim myReader As SqlDataReader = objCommand.ExecuteReader()
Do While myReader.Read
Console.WriteLine("{0}", myReader.GetString(2))
Loop
myReader.Close()
objCN.Close()
End Function
I have the below code for executing stored procedures and retreviing the returned value.
It works perfectly to execute procedures with no parameters, but as soon as I add parameters it errors with:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
Any help would be much appreciated, I have tried many types of example code from google with no luck.
Thanks
B
'Calling Code
MsgBox(SQLDataProvider_SP.execute_SP_ReturnParam(strConnectionString, "dbo.sp_mytestprocedure", "DBNAME"))
'Function
Public Shared Function execute_SP_ReturnParam(ByVal strConString As String, ByVal strSPName As String, ByVal strDBName As String)
Dim objCN As SqlConnection = New SqlConnection(strConString)
Dim objCommand As SqlCommand = New SqlCommand(strSPName, objCN)
objCommand.CommandTimeout = 20
objCommand.CommandType = CommandType.StoredProcedure
Dim inputValue As New SqlParameter("@iReturn", SqlDbType.Int)
inputValue.Direction = ParameterDirection.Output
objCommand.Parameters.Add(inputValue)
objCN.Open()
Dim myReader As SqlDataReader = objCommand.ExecuteReader()
Do While myReader.Read
Console.WriteLine("{0}", myReader.GetString(2))
Loop
myReader.Close()
objCN.Close()
End Function