Create DataTable


/ Published in: VB.NET
Save to your folder(s)

Howto create a new datatable manually


Copy this code and paste it in your HTML
  1. Public Function CreateDatatable() as DataTable
  2. ' Create new datatable
  3. Dim mydatatable As New DataTable
  4. ' Create columns
  5. mydatatable.Columns.Add("field_a", Type.GetType("System.String"))
  6. mydatatable.Columns.Add("field_b", Type.GetType("System.String"))
  7. ' Declare row
  8. Dim myrow As DataRow
  9. ' create new row
  10. myrow = mydatatable.NewRow
  11. myrow("field_a") = "filed a row 1"
  12. myrow("field_b") = "filed b row 1"
  13. mydatatable.Rows.Add(myrow)
  14. ' create another row
  15. myrow = mydatatable.NewRow
  16. myrow("field_a") = "filed a row 2"
  17. myrow("field_b") = "filed b row 3"
  18. mydatatable.Rows.Add(myrow)
  19. ' return the datatable filled with 2 columns and rows
  20. return mydatatable
  21. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.