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!
Printable View
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!
I'll assume you want the number to be your primary key:-
VB Code:
'declare dataset, datable and datacolumn dim ds as dataset dim dt as new datatable("SomeNames") dim dc as datacolumn 'create 2 datacolumns and add to the datable dc = new datacolumn dc.DataType = System.Type.GetType("System.Int32") dc.ColumnName = "id" dc.Unique = True dc.AutoIncrement = true dt.Columns.Add(dc) dc = new datacolumn dc.DataType = System.Type.GetType("System.String") dc.ColumnName = "Name" dt.Columns.Add(dc) 'set the id column as the primary key Dim PrimaryKeyColumns(0) As DataColumn PrimaryKeyColumns(0)= dt.Columns("id") dt.PrimaryKey = PrimaryKeyColumns 'add the datable to the dataset ds = new dataset ds.tables.add("SomeNames") 'now add some rows dim dr as datarow = dt.rows.newrow dr("Name") = "John Michigan" 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.
Thanx a bunch!!!