Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 get output parameter using odbc

Author  Topic 

dev45
Yak Posting Veteran

54 Posts

Posted - 2005-05-31 : 03:14:11
Hello all,
i apologise for posting this topic in this forum ,but i haven't been able to find an anwser anywhere else...so...

I am executing a stored procedure (on an SQL Server) using ODBC but i can't get the output parameter's value on the client. The stored proc has 3 parameters ,2 of them are input and 1 is output. (for shake of simplicity let's suppose that the proc seems something like
--------------------------------------------------------------------
alter storedProcsName @inputParam1 varchar(20), @inputParam2 varchar(20), @outputParam varchar(40) output
as
set @outputParam = @inputParam1 + @inputParam2
end
------------------------------------------------------------------

The vb.net code i am using is the following
----------------------------------------------------
Private Sub execODBC()
Dim a_string As String = "a_string"
Dim another_string As String = "another_string"
Dim a_dummy_string As String = "a_dummy_string"

Dim cmdObj As Odbc.OdbcCommand
Dim inputParam1 As Odbc.OdbcParameter
Dim inputParam2 As Odbc.OdbcParameter
Dim outputParam As Odbc.OdbcParameter

cmdObj = New Odbc.OdbcCommand

inputParam1 = cmdObj.Parameters.Add("@inputParam1",
Odbc.OdbcType.VarChar)
inputParam2 = cmdObj.Parameters.Add("@inputParam2",
Odbc.OdbcType.VarChar)
outputParam = cmdObj.Parameters.Add("@outputParam",
Odbc.OdbcType.VarChar)


inputParam1.Direction = ParameterDirection.Input
inputParam2.Direction = ParameterDirection.Input
outputParam.Direction = ParameterDirection.Output
outputParam.Size = 40

inputParam1.Value = a_string
inputParam2.Value = another_string
outputParam.Value = a_dummy_string

With cmdObj
.Connection = a_odbc_connection
.CommandType = CommandType.StoredProcedure

.CommandText = "{call storedProcsName('" & inputParam1.Value & " ','" & inputParam2.Value & "',?)}"

.ExecuteNonQuery()
End With

End Sub


When the code is executed, outputParam has a value of system.dbnull . Is there something wrong with the cmdObj.commandText assignement?

thanx
theodore
   

- Advertisement -