[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

add array to dataset

Posted on 2009-04-28
1
Medium Priority
?
2,619 Views
Last Modified: 2013-11-26
I have a 1 dimensional  array which is created by a nusoap webservice. I invoke this webservice with a vb,net windows form and would like to fill  a dataset with the contents of the array.

i have tried the code shown below but get the follwoing error

Input array is longer than the number of columns in this table

any help greatly appreciated
Public Function GetDataTableFromArray(ByVal array As Object()) As Data.DataSet
 
        Dim dataTable As New Data.DataTable()
 
        dataTable.Columns.Add("security")
        dataTable.Columns.Add("id")
        dataTable.Columns.Add("subject")
        dataTable.Columns.Add("duedate")
        dataTable.Columns.Add("percentcomplete")
        dataTable.Columns.Add("description")
        dataTable.Columns.Add("timezone")
        dataTable.Columns.Add("remind")
        dataTable.Columns.Add("recurrenceperiod")
        dataTable.Columns.Add("recurrenceenddate")
        dataTable.Columns.Add("recurrenceoccurences")
 
        dataTable.LoadDataRow(array, True) 'Pass array object to LoadDataRow method 
        Dim ds As New Data.DataSet
 
        ds.Tables.Add(dataTable)
 
        Return ds
 
    End Function

Open in new window

0
Comment
Question by:mm72
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 24253696
It's saying that your data table doesn't have enough columns to handle the array. Have you tried adding enough columns to equal the total number of elements that are in the array?
Public Function GetDataTableFromArray(ByVal array As Object()) As Data.DataSet
 
        Dim dataTable As New Data.DataTable()
 
        dataTable.Columns.Add("security")
        dataTable.Columns.Add("id")
        dataTable.Columns.Add("subject")
        dataTable.Columns.Add("duedate")
        dataTable.Columns.Add("percentcomplete")
        dataTable.Columns.Add("description")
        dataTable.Columns.Add("timezone")
        dataTable.Columns.Add("remind")
        dataTable.Columns.Add("recurrenceperiod")
        dataTable.Columns.Add("recurrenceenddate")
        dataTable.Columns.Add("recurrenceoccurences")
 
        For x As Integer = dataTable.Columns.Count To array.Length
            dataTable.Columns.Add("col" & x.ToString())
        Next
 
        dataTable.LoadDataRow(array, True) 'Pass array object to LoadDataRow method 
        Dim ds As New Data.DataSet
 
        ds.Tables.Add(dataTable)
 
        Return ds
 
    End Function

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question