Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to fill a Datatable with an Array.

Posted on 2014-03-24
4
Medium Priority
?
337 Views
Last Modified: 2014-04-13
Hi.

I am working with an external  WebService which  returns an array, but I cant recover the data on it.

I specifically need to recover two columns of the array and insert this values dynamically into a datatable. These colums names in the array are: DescripcionOT and FolioOT.

================= The code  in vb.Net is like this:  ============


 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim sesion_bodega As Integer = 2

        Dim OrdenesDeTrab As Array
        Dim WS_OTS As New WsInfoParaBodegas
        Dim TabOTs As New DataTable


        OrdenesDeTrab = WS_OTS.OrdenesEnEjecucion(2)

        Dim OTs As String
        Dim Desc_OT As String

        OTs = OrdenesDeTrab.Length.ToString

        ' in the debugging image the array.lenght  recovers 3 rows  (OTs= 3)
        ' Here I need to recover the 3 register in the array to fill up a data dable  (TabOTs ) 
        ' the array view is attached in the image. 


    End Sub

Open in new window

Array-values.jpg
0
Comment
Question by:Guvs89
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 39952788
Have you tried using <your data table>.Rows.Add(<your array>)?
0
 

Accepted Solution

by:
Guvs89 earned 0 total points
ID: 39986749
Dim OrdenesDeTrab As Array
            Dim WS_OTS As New WsInfoParaBodegas
            Dim TabOTs As New DataTable

            OrdenesDeTrab = WS_OTS.OrdenesEnEjecucion(sesion_bodega)
            TabOTs.Columns.Add("FolioOT", GetType(String))
            TabOTs.Columns.Add("DescripcionOT", GetType(String))

     
            For i As Integer = 0 To Convert.ToInt32(OrdenesDeTrab.Length) - 1

                If Not IsNothing(OrdenesDeTrab(i).DescripcionOT) Then
                    Dim N_reg As DataRow = TabOTs.NewRow
                    N_reg.Item("FolioOT") = OrdenesDeTrab(i).FolioOT.ToString
                    N_reg.Item("DescripcionOT") = OrdenesDeTrab(i).descripcionOT.ToString
                    TabOTs.Rows.Add(N_reg)

                Else

                    Mensaje.Text = " No se encontraron órdenes de trabajo de PSL "

                End If

            Next

            GV_OTs_PSL.DataSource = TabOTs
            GV_OTs_PSL.DataBind()
0
 

Author Closing Comment

by:Guvs89
ID: 39997119
I tryed several ways to recover de array data , by  my own trial and error process.
It  finally it worked.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

886 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