Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi, its me again.
I wanted to ask on <u>How to use (pass and return) array in function?</u>
I have this code on my Webservice project

WebMethod() _
      Public Function InsertProduk(ByVal key As Array, ByVal val As String, ByVal konter As Integer) As DataSet
        Dim conn As String
        Dim i As Integer = konter
        For a As Integer = 0 To i
            conn = &quot;server=localhost;uid=root;pwd=;database=miles&quot;
            Dim sql As String = &quot;insert into trade set id_pro="' + key(i) + '";
            Dim konek As New MySqlConnection(conn)
            Dim OdbcDa As New MySqlDataAdapter(Sql, conn)
            konek.Open()
            Dim ds As New DataSet
            OdbcDa.Fill(ds)
            konek.Close()
            Return ds
        Next
    End Function

This is what I imports in my webservice
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports MySql.Web
Imports MySql.Web.SessionState

But when I tr=ied to browse it, system throws me this error :
You must implement a default accessor on System.Array because it inherits from ICollection.
Posted
Updated 16-Jun-11 22:20pm
v5
Comments
Sergey Alexandrovich Kryukov 17-Jun-11 4:00am    
In what line of code?
--SA
satrio_budidharmawan 17-Jun-11 4:19am    
What do you mean with "what line code"?
thatraja 17-Jun-11 5:32am    
SA asked, "which line you are getting the error?"

1 solution

Your error is to do with the type of object that you are passing to your webservice. VB.NET is rather particular in what you can pass to it. I would have a look at this article

You must implement a default accessor on System.Array b...[^]

It would appear that you need to change the array to a generic list, there is an example of this in the article. Also to return a true dataset you will need to change

VB
Return ds


to, as the above will return a Diffgram[^]

VB
return ctype(ds, dataset)
 
Share this answer
 

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