Stephen William
Stephen William

Reputation: 3

How to return a value from class in VB

I have WCF C# class return two value to anther class , it is work fine but I need the same code in vb.net so I used convert C# to vb.net online site , the result the vb code :

<WebMethod(MessageName:="OpenAccount", Description:="this method create new account in the database"), _
System.Xml.Serialization.XmlInclude(GetType(ContactResult))> _
Public Function OpenAccount(ByVal Num As String, ByVal Pass As String) As ContactResult
    Dim ds As New DataSet
    Dim cr As New ContactResult
    Try
        Dim data As String
        Dim openCon As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\MONZER\Desktop\Karary Web Site\WebApplication1\App_Data\Database1.mdf;Integrated Security=True;User Instance=True")
        Dim da As SqlDataAdapter = New SqlDataAdapter("select * from Password", openCon)
        Dim saveStaff As String = "select Spec from Password where Num = @AndroidNum AND Pass = @AndroidPass"
        Dim querySaveStaff As SqlCommand = New SqlCommand(saveStaff)
        querySaveStaff.Connection = openCon
        querySaveStaff.Parameters.Clear()
        querySaveStaff.Parameters.AddWithValue("@AndroidNum", Num)
        querySaveStaff.Parameters.AddWithValue("@AndroidPass", Pass)
        openCon.Open()
        querySaveStaff.ExecuteNonQuery()
        ds.Clear()
        da.Fill(ds, "Password")
        data = ds.Tables("Password").Rows(0).Item(2).ToString
        openCon.Close()
        cr.ErrorID = 0
        cr.ErrorMessage = "vvvvvvvvvvvvvvvvvvvvv"
        Return cr
    Catch ex As Exception
        cr.ErrorID = 1
        cr.ErrorMessage = ex.Message
        Return cr
    End Try
End Function

return ErrorID and ErrorMessage to ContactResult class the ContactResult vb:

Public Class ContactResult
    Public Property ErrorID As Integer
        Get
        End Get
        Set(ByVal value As Integer)
        End Set
    End Property

    Public Property ErrorMessage As String
        Get
        End Get
        Set(ByVal value As String)
        End Set
    End Property
End Class

but it is not working it just return the ErrorID without ErrorMessage ,it is show like this in browser:

<ContactResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">

0

Upvotes: 0

Views: 139

Answers (1)

Vincent Vancalbergh
Vincent Vancalbergh

Reputation: 3327

Your property handlers don't do anything. So ErrorID remains 0 (the default value of Integer) and ErrorMessage remains at null (the default value of string). Seems the converter changed your Auto-Implemented Properties incorrectly:

public string PropertyName { get; set; }

to

Public Property PropertyName As String
    Get
    End Get
    Set(ByVal value As String)
    End Set
End Property

instead of

Public Property PropertyName As String

Try switching ContactResult to

Public Class ContactResult
    Public Property ErrorID As Integer
    Public Property ErrorMessage As String
End Class

Upvotes: 1

Related Questions