Posted By

miziomon on 01/12/07


Tagged

datatable


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

haoji


Create DataTable


 / Published in: VB.NET
 

Howto create a new datatable manually

  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  

You need to login to post a comment.