Untuk membuat datarow menggunakan bahasa pemograman VB.NET dapat dilakukan dengan cara berikut ini :
Private Sub CreateNewDataRow()' Use the MakeTable function below to create a new table.Dim table As DataTabletable = MakeNamesTable()' Once a table has been created, use the' NewRow to create a DataRow.Dim row As DataRowrow = table.NewRow()' Then add the new row to the collection.row("fName") = "John"row("lName") = "Smith"table.Rows.Add(row)Dim column As DataColumnFor Each column in table.ColumnsConsole.WriteLine(column.ColumnName)NextDataGrid1.DataSource=tableEnd SubPrivate Function MakeNamesTable() As DataTable' Create a new DataTable titled 'Names.'Dim namesTable As DataTable = new DataTable("Names")' Add three column objects to the table.Dim idColumn As DataColumn = new DataColumn()idColumn.DataType = System.Type.GetType("System.Int32")idColumn.ColumnName = "id"idColumn.AutoIncrement = TruenamesTable.Columns.Add(idColumn)Dim fNameColumn As DataColumn = New DataColumn()fNameColumn.DataType = System.Type.GetType("System.String")fNameColumn.ColumnName = "Fname"fNameColumn.DefaultValue = "Fname"namesTable.Columns.Add(fNameColumn)Dim lCalColumn As DataColumn = new DataColumn()lCalColumn.DataType = System.Type.GetType("System.Datetime")lCalColumn.ColumnName = "CalCol"namesTable.Columns.Add(lCalColumn)' Create an array for DataColumn objects.Dim keys(0) As DataColumnkeys(0) = idColumnnamesTable.PrimaryKey = keys' Return the new DataTable.MakeNamesTable = namesTableEnd Function
Have a nice day folks.
No comments:
Post a Comment