Link to home
Create AccountLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

Web service (vb.net) to return multiple parameters

code is a little buggy at the return statement, how do I return multiple paramters?

<WebMethod()> Public Function GetCities(ByVal State As String) As DataSet
     
        Try
     
            Dim dsn As String = "server=<xx.xx.xx.xx>;database=<Tessdext>;uid=sa;pwd="
            Dim myconnection As SqlConnection = New SqlConnection(dsn)
            myconnection.Open()
            ' ---
            Dim mycommand_TO_NUM As SqlDataAdapter = New SqlDataAdapter("select TO_NUMBER from message_queue ", myconnection)
            Dim ds_TO_NUM As New DataSet()
            mycommand_TO_NUM.Fill(ds_TO_NUM, "TO_NUMBER")
            myconnection.Close()
       
            ' ---
       
            Dim mycommand_MSG As SqlDataAdapter = New SqlDataAdapter("select MESSAGE from message_queue ", myconnection)
            Dim ds_MSG As New DataSet()
            mycommand_MSG.Fill(ds_MSG, "MESSAGE")
            myconnection.Close()
       
            Return (ds_TO_NUM, ds_MSG)
           
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Function
Avatar of leechoonhwee
leechoonhwee

Is this what you are looking for? Using one sql statement to return 2 columns?

Dim mycommand_TO_NUM As SqlDataAdapter = New SqlDataAdapter("select TO_NUMBER, Message from message_queue ", myconnection)

Well im guessing this is what you're looking for ...

https://www.experts-exchange.com/questions/20989347/convert-c-out-keyword-to-vb-net.html

good ol' expert exchange huh !!!!

Merry christmas !!!
ASKER CERTIFIED SOLUTION
Avatar of BuggyCoder
BuggyCoder
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Amandeep Singh Bhullar
You are sending two dataSets from the function namely "ds_TO_NUM" and "ds_MSG"

Whch is simply not possible.
Best solution is to create the response type obect with two properies as

Assign the values and return it to calling function
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Runtime.Serialization

<DataContract()> _
Public Class GetCitiesResponse
    Private ds_TO_NUM As DataSet
    Private ds_MSG As DataSet

    <DataMember()> _
    Public Property TO_NUM() As DataSet
        Get
            Return ds_TO_NUM
        End Get
        Set(ByVal value As DataSet)
            ds_TO_NUM = value
        End Set
    End Property

    <DataMember()> _
    Private Property MSG() As DataSet
        Get
            Return ds_MSG
        End Get
        Set(ByVal value As DataSet)
            ds_MSG = value
        End Set
    End Property
End Class

Open in new window