Solved

How to fill a Datatable with an Array.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

747 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

13 Experts available now in Live!

Get 1:1 Help Now