Click here to Skip to main content
11,496,146 members (801 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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 22:56pm
Edited 16-Jun-11 23: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

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 RyanDev 230
1 Sergey Alexandrovich Kryukov 114
2 Richard Deeming 100
3 OriginalGriff 89
4 Mostafa Asaduzzaman 59
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web01 | 2.8.150520.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