Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to fetch data from db from wcf service and send to my vb form but I am stuck when i got error " Value of type '1-dimensional array of Object' cannot be converted to 'System.Collections.ArrayList'." Here is my code please let me know improved code for this.

VB Code:
VB
Private Sub btn_login_submit_Click(sender As Object, e As EventArgs) Handles btn_login_submit.Click
        Dim loginService As LoginServiceReference.ILoginService
        Dim dt As New ArrayList
        dt = loginService.validateUser(txt_uname.Text, txt_psw.Text)

    End Sub
End Class



ILoginService.vb
XML
<ServiceContract()>
Public Interface ILoginService

    <OperationContract()>
    Function validateUser(uname As String, psw As String) As ArrayList

End Interface




ILoginService.svc.vb

VB
Function validateUser(ByVal uname As String, ByVal psw As String) As ArrayList Implements ILoginService.validateUser
       Dim userStatus As Boolean = False
       Dim dc As New UserLoginDataContext()
       Dim udata As ArrayList = From t In dc.User_LoginInfos Where t.UserName = uname & t.U_password = psw Select t

       If (udata.Count > 0) Then
           userStatus = True
       Else
           userStatus = False
       End If

       udata.Add(userStatus)
       Return udata
   End Function
Posted

1 solution

Here's a question.

Why are you even using ArrayList? It's pretty much been a dead collection since .NET 2.0 came out, back in 2005. I don't know anyone who uses it, for anything.

Next, a method called validateUser does not suggest, to me anyway, that it should be returning anything other than a Boolean value.

BTW, method names should not start with a lower case letter to differentiate them from camel-cased variable names.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-Dec-14 14:04pm    
Agree, a 5. Happy New Year!
—SA
bojammis 31-Dec-14 15:40pm    
Need to see class UserLoginDataContext
Dave Kreskowiak 31-Dec-14 21:54pm    
Be careful who you're replying to.

I don't need to see anything other than what the OP posted.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900