1

I have a function to get information on a SQL Server Table. I know the function is correct and returning everything as suposed too (I used msgBox to check it). The problem is when I try to use that function it displays an error:

enter image description here

My WCF Function:

    Public Function GetCLInfo(ByVal cl_ID As Integer) Implements SQLOperator.GetCLInfo
    Dim CLInfo(7) As String
    Try
        SQLCon.ConnectionString = SQLConString
        SQLCon.Open()

        SQLCMD = New SqlCommand("Select * from dbo.cl Where ID=" & cl_ID & ";", SQLCon)
        SQLDataReader = SQLCMD.ExecuteReader()

        While SQLDataReader.Read
            CLInfo(0) = SQLDataReader("ID")
            CLInfo(1) = SQLDataReader("Name")
            CLInfo(2) = SQLDataReader("Address")
            CLInfo(3) = SQLDataReader("Contact")
        End While

        Return CLInfo
    Catch ex As Exception
        MsgBox("Error: " & Environment.NewLine & ex.ToString)
        CLInfo(0) = "False"
        Return CLInfo
    Finally
        SQLCon.Close()
        SQLCon.Dispose()
    End Try

    Return CLInfo
End Function

In the picture you can see aswell how I'm trying to use the function.

Can someone kindly tell me what am I doing wrong?

Jay
  • 2,077
  • 5
  • 24
  • 39
rui404
  • 75
  • 1
  • 11
  • Your function doesn't specify what the return type is. Do you have `Option Strict On`? – Matt Wilko Mar 17 '16 at 11:19
  • Option Strict On? Sorry for my ignorance but I do not know what that is. I tried declaring the function specifying the return type. I used Public Function GetCLInfo(ByVal cl_ID As Integer) As String() .... Still did not worked! – rui404 Mar 17 '16 at 11:21
  • Read this: http://stackoverflow.com/questions/2454552/what-do-option-strict-and-option-explicit-do – Matt Wilko Mar 17 '16 at 11:23
  • Option Strick On or Off and Option Explict On or Off did not help. Thanks anyway. – rui404 Mar 17 '16 at 11:47

1 Answers1

0

Your problem is that you are calling a function to return string array and program doesn't catch by itself. As @Matt Wilko point out use Option Strict On. Second if you have more than one client your logic fails.

For I as integer = 1 to AllCl
Dim cl(7) as String
cl = Service.GetClInfo(I)
next

Above code will reset every each time, plus when you leave for loop you are loosing access to cl.

Ugly fix could be multidimensional array.

Now you should specify your return type

Public Function GetCLInfo(ByVal cl_ID As Integer) As String() Implements SQLOperator.GetCLInfo
Claudius
  • 1,883
  • 2
  • 21
  • 34