Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL stored procedure!

Posted on 2001-06-22
9
Medium Priority
?
212 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

885 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