Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL stored procedure!

Posted on 2001-06-22
9
Medium Priority
?
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Accepted Solution

by:
Felicitous earned 30 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 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