We Recommend

Beginning VB.NET Beginning VB.NET
Visual Basic .NET is the latest version of the most widely used programming language in the world, popular with professional developers and complete beginners alike. This book will teach you Visual Basic .NET from first principles. You'll quickly and easily learn how to write Visual Basic .NET code and create attractive windows and forms for the users of your applications.


Posted By

miziomon on 01/12/07


Tagged

datatable


Versions (?)


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.