Ado. NET object Construction (3)

Source: Internet
Author: User
Tags count one table tostring
Ado| Object n Overloads public Overridable Function Add () as DataTable

n Overloads Public Overridable Sub Add (ByVal table as DataTable)

n Overloads Public Overridable Function Add (ByVal name as String) as DataTable

N Public Sub AddRange (ByVal tables () as DataTable)

Parameters

1. Table the DataTable object to add.

2. Name to give the name of the DataTable that you have created.

3. Tables an array of DataTable objects to add to the collection.



DataTableCollection all DataTable objects that contain a specific DataSet. To access the DataSet's datatablecollection, use the Tables property.

DataTableCollection uses methods such as ADD, clear, and Remove to manage items in a collection.

Use the Contains method to determine whether a specific table is in the collection (specified by index or name).

To browse from one table to another, use the ChildRelations or ParentRelations properties of the DataTable to access the collection of its DataRelation objects. You can also use the Relations property to browse for a DataTables parent/child relationship in a given DataSet collection.



Example

Private Sub addtable ()

Dim DSet as dataset= CType (DataGrid1.DataSource, DataSet)

Dim DT as DataTable



DT = DSET.TABLES.ADD ("mynewtable")

MessageBox.Show (dt. TableName)

MessageBox.Show (dSet.Tables.Count.ToString () & "Tables")



Dim I as Integer

For i = 0 to 2

DSET.TABLES.ADD ()

Next I

MessageBox.Show (dSet.Tables.Count.ToString () & "Tables")



Dim tables as DataTableCollection = CType (DataGrid1.DataSource, DataSet). Tables

Tables. ADD (New DataTable)

MessageBox.Show (dSet.Tables.Count.ToString () & "Tables")



Dim T as DataTable

Dim R as DataRow

Dim C as DataColumn

For each T in Dset.tables

Console.WriteLine (T.tablename)

For each R in T.rows

For each C in T.columns

If Not (R (c) are nothing) Then

Console.WriteLine (R (c))

End If

Next

Next

Next



Dim T1 as DataTable = New DataTable ("Customers")

T1. Columns.Add ("CustomerId", Type.GetType ("System.Int32")). AutoIncrement = True

T1. Columns.Add ("Name", Type.GetType ("System.String"))

T1. PrimaryKey = New DataColumn () {t1. Columns ("CustomerId")}



Dim T2 as DataTable = New DataTable ("Orders")

T2. Columns.Add ("OrderId", Type.GetType ("System.Int32")). AutoIncrement = True

T2. Columns.Add ("CustomerId", Type.GetType ("System.Int32"))

T2. Columns.Add ("Amount", Type.GetType ("System.Double"))

T2. PrimaryKey = New DataColumn () {t2. Columns ("OrderId")}



DSet.Tables.AddRange (New DataTable () {t1, t2})



For each T in Dset.tables

Console.WriteLine (T.tablename)

For each C in T.columns

Console.Write ("{0}" & VbTab, C.columnname)

Next

Console.WriteLine ()

Next

MessageBox.Show (dSet.Tables.Count.ToString () & "Tables")

End Sub



Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.