Solved

How to fill a Datatable with an Array.

Posted on 2014-03-24
4
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

739 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