Results 1 to 8 of 8

Thread: Problem with ADO Parameter value [resolved]

  1. #1

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531

    Problem with ADO Parameter value [resolved]

    Anyone out there know how to pass a sql statement as a parameter value?

    Code:
    Set para = cmdCommand.CreateParameter("estimate_id", adNumeric, adParamReturnValue, 20, "SELECT NVL(MAX(estimate_id) + 1,1) FROM time_estimates")
    cmdCommand.Parameters.Append para
    I'm sure there is a way to do this - maybe with the right data type and parameter type combination (2nd and 3rd arguments in CreateParameter method)....I'll keep checking the web, but if anyone has done this before, please demonstrate. Thanks.
    Last edited by ahara; Apr 22nd, 2004 at 04:09 AM.
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Why not run the SQL query first, return the recordset with the number you want, and then use this number as the parameter:

    eg: (I haven't got VB handy so my syntax may not be 100%)

    VB Code:
    1. Dim tmpRS As New ADODB.Recorset
    2. Dim tmpResult AS Double
    3.  
    4. tmpRS.Open "SELECT NVL(MAX(estimate_id) + 1,1) AS TempResult FROM time_estimates",[connection],adOpenStatic, adOpenReadOnly
    5.  
    6. tmpResult = tmprs.Fields("TempResult")
    7. tmpRS.Close
    8.  
    9. Set para = cmdCommand.CreateParameter("estimate_id", adNumeric, adParamReturnValue, 20, tmpResult)
    10. cmdCommand.Parameters.Append para
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    appreciate your reply, but it was like that before I began changing it....we have decided here to modify some of our apps and take advantage of Oracle's caching capabilities - we are trying to minimize db queries....parameter objects are being implemented everywhere, but this is the first time I am trying to pass a statement.
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  4. #4
    Hyperactive Member
    Join Date
    May 2003
    Posts
    401
    Why dont you store the sql statement in a variable and call the variable instead?? Something like:

    VB Code:
    1. Dim strSQL as String
    2. strSQL="SELECT NVL(MAX(estimate_id) + 1,1) FROM time_estimates"
    3. Set para = cmdCommand.CreateParameter("estimate_id", adNumeric, adParamReturnValue, 20, strSQL)
    4. cmdCommand.Parameters.Append para

    I hope this helps.
    Enjoy!!!
    apps_tech

  5. #5

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    yeah I hear ya, and thanks for looking at it - I am actually trying to see if I can do it all in one statement without hitting the db. I suspect however that it is not possible to do afterall.
    Thanks again
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The last argument of the CreateParameter function is the Value of the parameter not an SQL statement.

    The SQL Statement in your original post does not even have to use parameters.

    Here is how to use the ADO Command object to execute a procedure( that requires parameters).

    VB Code:
    1. Set objCMD = New ADODB.Command
    2. With objCMD
    3.     Set .ActiveConnection = Some ADO Connection object
    4.     .CommandText = "Select * From SomeTable Where Field1 = ? And Field2 = ?"
    5.     .CommandType = adCmdText
    6.     .Parameters.Append .CreateParameter("RetValue", adInteger, adParamReturnValue)
    7.  
    8.     .Parameters.Append .CreateParameter("Field1", Datatype, Direction, Size, Value)
    9.     .Parameters.Append .CreateParameter("Field1", Datatype, Direction, Size, Value)
    10.  
    11.     .Execute ,,adExecuteNoRecords 'Action queries
    12.  
    13.     Set RecordSetObject = .Execute 'Row returning queries
    14.  
    15. End With

    The ADO Command object always returns an Read Only Forward Only cursor (for row returning queries).

    Use the RecordSet.Open method to create a specific cursor type.

    RecordsetObject.Open objCMD, , adOpenStatic, adLockReadOnly

  7. #7

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    thanks very much for the info brucevde (especially the cursor bit - makes a lot of sense) cheers
    "Knowledge is gained when different people look at the same information in different ways"

    - Louis Pasteur

  8. #8
    Hyperactive Member rplcmint's Avatar
    Join Date
    Jan 2001
    Location
    Stockton, CA
    Posts
    333
    This is a very informative subject that I easily forgot about! I can use this in my app.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width