Click here to Skip to main content
11,576,692 members (57,023 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET WebService
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)
            Dim ds As New DataSet
            Return ds
    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 16-Jun-11 21:56pm
Edited 16-Jun-11 22:20pm
SAKryukov at 17-Jun-11 4:00am
In what line of code?
satrio_budidharmawan at 17-Jun-11 4:19am
What do you mean with "what line code"?
thatraja at 17-Jun-11 5:32am
SA asked, "which line you are getting the error?"

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

 Return ds

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

 return ctype(ds, dataset)

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 251
1 Abhinav S 170
2 DamithSL 105
3 Lucifier Rocks 105
4 Dave Kreskowiak 80
0 OriginalGriff 715
1 Sergey Alexandrovich Kryukov 631
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 365

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 17 Jun 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100