Solved

How to fill a Datatable with an Array.

Posted on 2014-03-24
4
320 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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now