Solved

SQL stored procedure!

Posted on 2001-06-22
9
203 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

679 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