Solved

SQL stored procedure!

Posted on 2001-06-22
9
202 Views
Last Modified: 2008-02-01
here is a peice of code that is giving an error:
"Optional feature not implemented"
' code

    Dim cmd As New ADODB.Command, storedParam(6) As New ADODB.Parameter
    cmd.ActiveConnection = dbCon.ConnectionString
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "storedProcName"
   
    storedParam(0).Type = adBSTR
    storedParam(0).Size = 10
    storedParam(0).Direction = adParamInput
    storedParam(0).Value = cust_id
    cmd.Parameters.Append storedParam(0)
.... ' continues with other parameters, one of them is of date type
' code ends here

on executing the statement
cmd.execute , affectedRecords

i am missing something here and very minor i guess
i have tried to use a different cursor for my dbCon variable and now not using any! still giving problems!
0
Comment
Question by:TinasheC
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:vindevogel
ID: 6217923
Have you declared the AffectedRecords variable somewhere ?
0
 
LVL 5

Expert Comment

by:bob_online
ID: 6218096
Doesn't matter what you've set in your dbConn variable, because you're not using it.

You're setting a new connection for your command object.

Use this:

cmd.ActiveConnection = dbCon
0
 

Author Comment

by:TinasheC
ID: 6218328
well this is where I am now!
    cmd.ActiveConnection = dbCon
    cmd.CommandType = adCmdStoredProc
    cmd.CommandText = "storedProcName"

    storedParam(0).Type = adVarChar
    storedParam(0).Size = 9
    storedParam(0).Direction = adParamInput
    storedParam(0).Value = someStringValue
    storedParam(0).Attributes = 64
    storedParam(0).Name = "@param_name"
    'cmd.Parameters.Append storedParam(0) 'Line No# 1
    cmd.Parameters.Item(2) = storedParam(0)'Line No# 2
Dim cmd As New ADODB.Command, storedParam(6) As New ADODB.Parameter

i have tried line no# 1 and line no# 2 seperately if i try one it will append additional parameters over and above the ones required by the stored procedure and it will give an error "SQL requires a parameter ... which is not set "

line no# 2 its complaining bitterly about value being of different types.




0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Accepted Solution

by:
Felicitous earned 10 total points
ID: 6222101
Hi,

hope this is of some help. Here is an example piece of code I use to call SQL 7.0 stored procedures from VB. I use the Variant datatype and avoid typing issues, although it still has to be compatible between the SQL type and the VB type in the end. Hope it helps.


    Dim DB_Command As ADODB.Command
    Dim DB_Param(5) As Variant
   
    Set DB_Command = New ADODB.Command
    DB_Command.ActiveConnection = pmConnection
    DB_Command.CommandType = adCmdStoredProc
    DB_Command.CommandText = "pm_insert_NAME"
    DB_Param(0) = pmName_Same_Person_Key
    DB_Param(1) = pmName_Title
    DB_Param(2) = pmName_Leading_Initial
    DB_Param(3) = pmName_Initials
    DB_Param(4) = pmName_Christian_Name
    DB_Param(5) = pmName_Surname
   
    DB_Command.Execute , DB_Param

Regards,

Graham
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6383706
Not even a comment why the answer is accepted, nor why a B is given ...
Some people really think the experts are just to be used to ask questions.  No respect at all.
0
 

Author Comment

by:TinasheC
ID: 6383779
it worked, so i feel he deserved it
0
 

Expert Comment

by:Felicitous
ID: 6386561
There is a drawback with the method I proposed.

It is only really useful for stored procedures which do not return results.

If you are going to return a result (either through the Return Value or other OUTPUT parameter) then the code I suggested does not work.

Here is some example code which does work in this situation:

Public Function AddNew() As Integer

On Error GoTo Err_Label

    Dim DB_Command As ADODB.Command
   
    Set DB_Command = New ADODB.Command
   
    DB_Command.ActiveConnection = pmConnection
    DB_Command.CommandType = adCmdStoredProc
    DB_Command.CommandText = "pm_insert_GUILD"
   
    With DB_Command.Parameters
        .Append DB_Command.CreateParameter("ReturnValue", adInteger, adParamReturnValue, , 0)
        .Append DB_Command.CreateParameter("@Guild_Name_2", adVarChar, adParamInput, 255, pmGuild_Name)
        .Append DB_Command.CreateParameter("@Guild_Coat_Of_Arms_4", adVarChar, adParamInput, 255, pmGuild_Coat_Of_Arms)
        .Append DB_Command.CreateParameter("@Guild_Information_5", adLongVarChar, adParamInput, 2048, pmGuild_Information)
        .Append DB_Command.CreateParameter("@Guild_Identity_6", adInteger, adParamInputOutput, , pmIdentity)
    End With

    DB_Command.Execute , , adCmdStoredProc
   
    AddNew = DB_Command.Parameters("ReturnValue")
    pmGuild_Identity = DB_Command.Parameters("@Guild_Identity_6")
   
    Exit Function

Err_Label:

Sorry about the line feeds etc. If you need help on typing variables (eg SQL 7 to VB etc) drop me a line and will try to help.

Regards,

Graham

ghill@felicitous.com
0
 
LVL 4

Expert Comment

by:vindevogel
ID: 6387823
If he/she deserved the points, then show your appriciation by just saying thank you.
0
 

Expert Comment

by:Felicitous
ID: 6388195
My last post (definative).

There is no thanks necessary.

People on Experts have helped me and I just like to return the favour :-)

Enjoy life, its all too short :-)

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 51
Help me. 3 60
How to read File Date Created using VB6 8 52
Error with a code discussed on this page 5 32
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question