Solved

SQL stored procedure!

Posted on 2001-06-22
9
200 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
Comment Utility
Have you declared the AffectedRecords variable somewhere ?
0
 
LVL 5

Expert Comment

by:bob_online
Comment Utility
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
Comment Utility
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
 

Accepted Solution

by:
Felicitous earned 10 total points
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 4

Expert Comment

by:vindevogel
Comment Utility
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
Comment Utility
it worked, so i feel he deserved it
0
 

Expert Comment

by:Felicitous
Comment Utility
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
Comment Utility
If he/she deserved the points, then show your appriciation by just saying thank you.
0
 

Expert Comment

by:Felicitous
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now