Results 1 to 6 of 6

Thread: problems converting code

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    problems converting code

    ok, I found this sample on the internet:http://authors.aspalliance.com/steve...les/sprocs.asp

    I can't seem to figure out how to make it optimal for vb.net
    Below is the sample code and below that, my code. I have mine in a function and it's called from a try block so I don't know what error exactly is being caught (I COULD, just too lazy right now lol)

    What I'm having problems with is the SET command, I THINK I got that, you tell me.



    VB Code:
    1. Dim objConn
    2. Dim objCmd
    3.  
    4. 'Instantiate objects
    5. Set objConn     = Server.CreateObject("ADODB.Connection")
    6. set objCmd      = Server.CreateObject("ADODB.Command")
    7. conn.Open Application("ConnectionString")
    8.  
    9. With objCmd
    10.     .ActiveConnection = conn 'You can also just specify a connection string here
    11.     .CommandText = "sp_InsertArticle"
    12.     .CommandType = adCmdStoredProc 'Requires the adovbs.inc file or typelib meta tag
    13.    
    14.     'Add Input Parameters
    15.     .Parameters.Append .CreateParameter("@columnist_id", adDouble, adParamInput, , columnist_id)
    16.     .Parameters.Append .CreateParameter("@url", adVarChar, adParamInput, 255, url)
    17.     .Parameters.Append .CreateParameter("@title", adVarChar, adParamInput, 99, url)
    18.     .Parameters.Append .CreateParameter("@description", adLongVarChar, _
    19.         adParamInput, 2147483647, description)
    20.    
    21.     'Add Output Parameters
    22.     .Parameters.Append .CreateParameter("@link_id", adInteger, adParamOutput, , 0)
    23.        
    24.     'Execute the function
    25.     'If not returning a recordset, use the adExecuteNoRecords parameter option
    26.     .Execute, , adExecuteNoRecords
    27.     link_id = .Parameters("@link_id")
    28. End With

    VB Code:
    1. Public Function GetTicketNumber(ByVal Customer As String) As Integer
    2.         'Purpose    :   gets a ticket number for each ticket.  SP in database
    3.         'Accepts    :   customer name
    4.         'Notes      :   SP does all the work
    5.         Dim i As Integer
    6.  
    7.         With AdoCmd
    8.             .ActiveConnection = DB
    9.             .CommandText = "GenerateTicketNumber"
    10.             .CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
    11.  
    12.             .Parameters.Append(.CreateParameter("@Name", ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, , Customer))
    13.             .Parameters.Append(.CreateParameter("@TicketNumber", ADODB.DataTypeEnum.adInteger, ADODB.ParameterDirectionEnum.adParamInputOutput, , 0))
    14.             .Execute()
    15.  
    16.         End With
    17.  
    18.     End Function

    Here are the variables. I use the connection and recordse objects throughout the project. It may be that I can't use those same objects in my adocmd object?

    VB Code:
    1. Public DB As New ADODB.Connection           'This is for a global ado database connection
    2.     Public RS As New ADODB.Recordset            'This is for a global ado recordset
    3.     Public AdoCmd As New ADODB.Command          'Used for Stored Procedures

    I am TOTALY lost on this one. I don't have an option BUT to use ado or I'd use ado.net.

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    another thing that's throwing me off is where he uses:

    VB Code:
    1. conn.open.......

    I don't see a conn declared::?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok, I've scratched that code. i don't think it's what I need. I have combed these forums and googled till my google is dry... Is it even POSSIBLE to call a stored proc, using ADO, using visual basic.NET? I know there has to be but I can't find examples in any language other than asp, vb6 or other older languages


    HELP

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Well... first off in .NET, there is not such thing as the SET command.....as all things are now objects.

    And I think conn was supposed to be objConn.....

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    Originally posted by techgnome
    Well... first off in .NET, there is not such thing as the SET command.....as all things are now objects.

    And I think conn was supposed to be objConn.....

    TG
    That's exactly what I thought thanks.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    ok, I finally got everything (for THIS problem)solved...for now lol

    I ended up using ado.net (against my project leader's orders ) and used an sqlconnection, sqlcommand and made a function to hit the stored procedure and return a value for me.

    Thanks for all the help y'all

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