Results 1 to 3 of 3

Thread: create a dataset

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    9

    create a dataset

    1 John Michigan
    2 Karl California
    3 Meg Iowa

    I have a list box with the items shown above..
    Can some one tell me how to create a dataset table.

    Thanx!

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I'll assume you want the number to be your primary key:-

    VB Code:
    1. 'declare dataset, datable and datacolumn
    2. dim ds as dataset
    3. dim dt as new datatable("SomeNames")
    4. dim dc as datacolumn
    5.  
    6. 'create 2 datacolumns and add to the datable
    7. dc = new datacolumn
    8. dc.DataType = System.Type.GetType("System.Int32")
    9. dc.ColumnName = "id"
    10. dc.Unique = True
    11. dc.AutoIncrement = true
    12. dt.Columns.Add(dc)
    13. dc = new datacolumn
    14. dc.DataType = System.Type.GetType("System.String")
    15. dc.ColumnName = "Name"
    16. dt.Columns.Add(dc)
    17.  
    18. 'set the id column as the primary key
    19. Dim PrimaryKeyColumns(0) As DataColumn
    20. PrimaryKeyColumns(0)= dt.Columns("id")
    21. dt.PrimaryKey = PrimaryKeyColumns
    22.  
    23. 'add the datable to the dataset
    24. ds = new dataset
    25. ds.tables.add("SomeNames")
    26.  
    27. 'now add some rows
    28. dim dr as datarow = dt.rows.newrow
    29. dr("Name") = "John Michigan"
    30. dt.rows.add(dr)

    You can of course create 2 string columns for first and second name if you wish. As usual I leeched this code from the .net docs. Always worth checking it out.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Posts
    9
    Thanx a bunch!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width