VB ADO Help

Status
Not open for further replies.

Tabibito

Ars Scholae Palatinae
1,316
Ok, I need to execute an SQL procedure from my VB program, but the procedure is a delete, so no recordset is returned. However, my compiler (VS6.0) complains when I try to use the Execute method for an ADODB.Command object without setting the result equal to something. Do I need to make a temprorary ADODB.Recordset that never gets used to appease the compiler, or is there something I'm not doing here?

Edit: I'm using the ActiveX 2.5 libraries if it makes any difference
 

kleel

Ars Scholae Palatinae
1,022
does your stored proc return anything?

I've had problems before when I left the return statement in which is added by default in Interdev6 when creating a SP.

Normally I use this template for calling SPs .... let me know if it works ;)

Code:
Dim SQLConn as string : SQLConn ="insert your DB connection string here"
Dim Conn As New ADODB.Connection
Dim Cmd As New ADODB.Command
    
'open connection to db
Conn.Open SQLConn
    
' set up SP's Parameters - RETURN VALUE is always needed even when your SP doesnt return anything!
Cmd.Parameters.Append Cmd.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue)
    
' template for an input parameter
'oCmd.Parameters.Append oCmd.CreateParameter("@ID",adInteger,adParamInput,0, value)
    
' template for an Output parameter
'oCmd.Parameters.Append oCmd.CreateParameter("@ReturnID",adInteger,adParamInputOutput,0,null)

Cmd.CommandType = adCmdStoredProc
Cmd.CommandText = "my_StoredProcName"
Cmd.ActiveConnection = Conn
Cmd.Execute
    
    
' tidy up    
set Cmd=nothing
Conn.close
set Conn=nothing
 
Status
Not open for further replies.