Question

I am developing Visual Basic 6 code for call to a Microsoft SQL Server function, but...I can't get it do work ...

The T-SQL code:

ALTER FUNCTION [dbo].[fnRutaFichero](@ID_FICHERO VARCHAR(256))
   RETURNS varchar(256)
AS
   .
   .
   .
   RETURN (@rutaFichero)
END

The VB6 code:

Set cnn = New ADODB.Connection
cnn.ConnectionString = cStrConn
cnn.Open "File Name=" & App.Path & "\Config\VCH2.udl;"

Set cmd = New ADODB.Command
cmd.ActiveConnection = cnn
cmd.CommandTimeout = 15
cmd.CommandType = adCmdText

cmd.CommandText = "SELECT fnRutaFichero(@ID_FICHERO)"

cmd.Parameters.Append cmd.CreateParameter("@ID_FICHERO", adVarChar, adParamInput, , "VCH2")

cmd.Execute

I don't understand how to do this task...

Thanks...

Was it helpful?

Solution

Normally you would make a command = a resordset.

Set objRs = objCmd.Execute

Here's the programmers guide http://msdn.microsoft.com/en-us/library/windows/desktop/ms675065(v=vs.85).aspx

Also not all commands can be done via ADODB according to the docs http://msdn.microsoft.com/en-us/library/windows/desktop/ms677502(v=vs.85).aspx.

Use a Command object to query a database and return records in a Recordset object, to execute a bulk operation, or to manipulate the structure of a database. Depending on the functionality of the provider, some Command collections, methods, or properties may generate an error when they are referenced.

OTHER TIPS

You need to have a return value added to the list of parameters, and you have to include the size of the VarChar field:

cmd.Parameters.Append cmd.CreateParameter("@rutaFichero", adVarChar, adParamReturnValue, 256)
cmd.Parameters.Append cmd.CreateParameter("@ID_FICHERO", adVarChar, adParamInput, 256, "VCH2")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top