borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Run-time Error assigning text to/from textbox - error 2185)Next Topic (Embedding MSDE 2000 Setup Into Custom Applications Setup) New Topic New Poll Post Reply
AndreaVB Forum : Database : sql function return few paramets? Solved Topic
Poster Message
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 161

icon sql function return few paramets?

hi all. can i create sql function can return more than a paramet?

____________________________
Please help out.

16-05-2006 at 11:15 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: sql function return few paramets?

I don't know if this is exactly what you mean but in SQL Server you can create a stored procedure with input and output parameters. Input parameters are passed to the function, output parameters are returned by the stored procedure.

here's an example of a SP definition:

CREATE PROCEDURE test(@input1 integer,@output1 integer OUTPUT, @output2 varchar(13) OUTPUT,@output3 smallint OUTPUT) AS

SELECT @output1=@input1+1
SELECT @output2='HELLO'
SELECT @output3=10

SELECT * FROM My_Table


This SP returns three output parameters and takes one for input, it also returns a recordset...

hope this helps

____________________________
AndreaVB

16-05-2006 at 12:05 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
luckyboy
Level: VB Lord

Registered: 05-05-2005
Posts: 161
icon Re: sql function return few paramets?

can i used your store procedure like this
dim output1 as integer
dim output2 as string
dim output3 as byte
con.execute "Exec  test 1," & output1 & "," & output2 & "," & output3

can output1=1
      output2=hello
      output3=10


____________________________
Please help out.

17-05-2006 at 01:55 AM
View Profile Send Email to User Show All Posts | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: sql function return few paramets?

Are you using ADO to connect?

____________________________
AndreaVB

17-05-2006 at 06:03 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
admin
Level: Administrator


Registered: 04-04-2002
Posts: 530
icon Re: sql function return few paramets?

anyway here's the ADO code

Private Sub Command1_Click()
    Const myServerName = "MYSERVER"
    Const myUID = "sa"
    Const myPassword = "mypassword"
    Const myDatabase = "myDB"
    
    Dim conn As ADODB.Connection
    Dim sp As ADODB.Command

    Set conn = New ADODB.Connection
    conn.Open "driver={SQL Server};server=" & myServerName & ";UID=" & myUID & ";PWD=" & myPassword & ";database=" & myDatabase
    Set sp = New ADODB.Command
    Set sp.ActiveConnection = conn
    sp.CommandText = "{Call test(?,?,?,?)}"
    'set the input parameters
    sp.Parameters(0) = 1
    sp.Parameters(1) = 0
    sp.Parameters(2) = ""
    sp.Parameters(3) = 0
    sp.Execute
    MsgBox "Param 1:" & sp.Parameters(1) & vbCrLf & _
        "Param 2:" & sp.Parameters(2) & vbCrLf & _
        "Param 3:" & sp.Parameters(3)
    conn.Close
    Set conn = Nothing
End Sub


[Edited by admin on 17-05-2006 at 01:08 PM GMT]

____________________________
AndreaVB

17-05-2006 at 12:08 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
AndreaVB Forum : Database : sql function return few paramets? Solved Topic
Previous Topic (Run-time Error assigning text to/from textbox - error 2185)Next Topic (Embedding MSDE 2000 Setup Into Custom Applications Setup) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder