Return to Snippet

Revision: 2188
at January 12, 2007 08:06 by miziomon


Updated Code
Public Function CreateDatatable() as DataTable
        ' Create new datatable
        Dim mydatatable As New DataTable
        ' Create columns
        mydatatable.Columns.Add("field_a", Type.GetType("System.String"))
        mydatatable.Columns.Add("field_b", Type.GetType("System.String"))
        ' Declare row
        Dim myrow As DataRow
        ' create new row
        myrow = mydatatable.NewRow
        myrow("field_a") = "filed a row 1"
        myrow("field_b") = "filed b row 1"
        mydatatable.Rows.Add(myrow)
        ' create another row
        myrow = mydatatable.NewRow
        myrow("field_a") = "filed a row 2"
        myrow("field_b") = "filed b row 3"
        mydatatable.Rows.Add(myrow)
        ' return the datatable filled with 2 columns and rows
        return mydatatable
End Sub

Revision: 2187
at January 12, 2007 07:49 by miziomon


Initial Code
Private Sub datatablemanuale()

        ' creazione dati


        Dim mydatatable_appointments As New DataTable

        ' creazione colonne con i dati
        mydatatable_appointments.Columns.Add("orario", Type.GetType("System.String"))
        mydatatable_appointments.Columns.Add("name", Type.GetType("System.String"))
        mydatatable_appointments.Columns.Add("surname", Type.GetType("System.String"))

        Dim myrow As DataRow


        myrow = mydatatable_appointments.NewRow

        myrow("orario") = "8.00"
        myrow("name") = "maurizio"
        myrow("surname") = "pelizzone"

        mydatatable_appointments.Rows.Add(myrow)



        myrow = mydatatable_appointments.NewRow

        myrow("orario") = "9.00"
        myrow("name") = "diego"
        myrow("surname") = "grosso"

        mydatatable_appointments.Rows.Add(myrow)

        myrow = mydatatable_appointments.NewRow

        myrow("orario") = "11.00"
        myrow("name") = "dario"
        myrow("surname") = "blengio"

        mydatatable_appointments.Rows.Add(myrow)


    End Sub

Initial URL

                                

Initial Description
Howto create a new datatable manually

Initial Title
Create DataTable

Initial Tags

                                

Initial Language
VB.NET