Ado| Object DataTable Construction
N Public Sub New ()
N Public Sub New (ByVal tablename as String)
n Protected Sub New (ByVal info as SerializationInfo, ByVal context as StreamingContext)
Parameters
1. Info The data required to serialize or deserialize an object.
2. Context given the source and destination of the serialized stream.
3. TableName assigns the name of the table. If it is a null reference (Nothing in Visual Basic) or an empty string, the default name is provided when added to DataTableCollection.
A DataTable is a core object in a ado.net library. Other objects that use the DataTable include datasets and DataView.
When accessing a DataTable object, note that they are case-sensitive. For example, if a DataTable is named "Mydatatable" and the other is named "Mydatatable", the string used to search for one of the tables is considered case-sensitive. However, if "mydatatable" exists and "mydatatable" does not exist, the search string is considered case-insensitive.
If you are creating a DataTable programmatically, you must first define its schema by adding the DataColumn object to DataColumnCollection (accessed by Columns property).
To add rows to a DataTable, you must first return the new DataRow object using the NewRow method. The NewRow method returns the row of the schema with the DataTable, as defined by the table's datacolumncollection. The maximum number of rows a DataTable can store is 16,777,216.
The schema of the table is datacolumncollection defined by the collection of DataColumn objects. Access DataColumnCollection through the Columns property.
A DataTable contains a collection of Constraint objects that can be used to ensure data integrity.
Example
Private Sub Makedatatableanddisplay ()
' Create new DataTable.
Dim mydatatable as New DataTable
Dim mydatatable as DataTable = New DataTable ("Mydatatable")
' Declare DataColumn and DataRow variables.
Dim Mydatacolumn as DataColumn
Dim MyDataRow as DataRow
' Create new DataColumn, set DataType, ColumnName and add to DataTable.
Mydatacolumn = New DataColumn
Mydatacolumn.datatype = System.Type.GetType ("System.Int32")
Mydatacolumn.columnname = "id"
MYDATATABLE.COLUMNS.ADD (Mydatacolumn)
' Create second column.
Mydatacolumn = New DataColumn
Mydatacolumn.datatype = Type.GetType ("System.String")
Mydatacolumn.columnname = "Item"
MYDATATABLE.COLUMNS.ADD (Mydatacolumn)
' Create new DataRow objects and add to DataTable.
Dim I as Integer
For i = 0 to 10
MyDataRow = Mydatatable.newrow
MyDataRow ("id") = I
MyDataRow ("item") = "Item" & I
MYDATATABLE.ROWS.ADD (MyDataRow)
Next I
"Set to Datagrid.datasource" to the table.
DataGrid1.DataSource = mydatatable
End Sub
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.