create a new datatable


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

This code will sow you how to create a new datatable


Copy this code and paste it in your HTML
  1. 'creating new datatable
  2. dim productTable as new datatable("Products")
  3. 'build the producs schema
  4. products.columns.add("id", gettype(system.int32)
  5. products.columns.add("Name", gettype(system.int32)
  6. products.columns.add("Address", gettype(system.string)
  7. products.columns.add("Tel", gettype(system.string)
  8.  
  9. 'Seting up the ID column as the primary key
  10. producttable.primarykey=new datacolumn() {productstable.columns("ID")}
  11. producttable.columns("ID").autoincrement=true
  12. producttable.columns("ID").autoincrementSeed=1
  13. producttable.columns("ID").readonly=true
  14.  
  15. 'now we are going to populate the datatable with data and for that we need datarow object
  16. dim Guste as new Datarow=productstable.newrow()
  17. 'set the column values
  18. Guste.item("ID")=1
  19. Guste.item("Name")="Nasser M. Tabook"
  20. Guste.item("Address")="Sultanate of oman, Dhofar, Salalah , p.o .box 2557"
  21. Guste.item("Tel")="123456789"
  22. 'Add the datarow to the datatable
  23. productstable.rows.add(Guste)
  24. '
  25. '
  26. '
  27. '
  28. '------------------------------------------------------------------------------------
  29. 'Another way to fill the newlly created database with data
  30. '
  31. '
  32. '
  33. dim Guste as datarow
  34. gueste("Name")="Nasser M. Tabook"
  35. gueste("Address")="Sultanate of oman, Dhofar, Salalah , p.o .box 2557"
  36. gueste("Tel")="123456789"
  37. producttable.rows.add("Guest")
  38.  
  39. 'creating new xml file to hold the data
  40. producttable.writexml("producttable.xml") 'or you can use producttable.writexml(Server.MapPath("producttable.xml")

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.