A brief introduction to some new features of ado.net2.0 and ado.net3.0

Source: Internet
Author: User
Tags foreach new features query
Ado

Feel that a lot of people are writing about asp.net2.0, few people write about the new features of ado.net2.0. Looked up the MSDN, to introduce you a few good points. (If you need to see new features for all ado.net2.0, check the

http://msdn2.microsoft.com/en-us/library/ex6y04yf.aspx)

Server Enumeration

An instance of SQL Server that is used to enumerate the active state, and the version needs to be SQL2000 and updated. The Sqldatasourceenumerator class is used.

You can refer to the following sample code:

Using SYSTEM.DATA.SQL;

Class Program
{
static void Main ()
{
Retrieve the enumerator instance and then the data.
Sqldatasourceenumerator instance =
Sqldatasourceenumerator.instance;
System.Data.DataTable table = instance. Getdatasources ();

Display the contents of the table.
Displaydata (table);

Console.WriteLine ("Press any key to continue.");
Console.readkey ();
}

private static void Displaydata (System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table). Rows)
{
foreach (System.Data.DataColumn col in table). Columns)
{
Console.WriteLine ("{0} = {1}", Col.) ColumnName, Row[col]);
}
Console.WriteLine ("============================");
}
}
}

DataSet Enhancements

The new DataTableReader class can be said to be a dataset or a DataTable, one or more read-only, forward-only result sets. It is necessary to note that the DataTableReader returned by the DataTable does not contain rows that are marked as deleted.

Example:

private static void Testcreatedatareader (DataTable dt)
{
Given a DataTable, retrieve a DataTableReader
Allowing access to all the tables ' data:
using (DataTableReader reader = dt. CreateDataReader ())
{
Todo
{
if (!reader. HasRows)
{
Console.WriteLine ("Empty DataTableReader");
}
Else
{
PrintColumns (reader);
}
Console.WriteLine ("========================");
} while reader. NextResult ());
}
}

private static DataTable GetCustomers ()
{
Create Sample Customers table, in order
To demonstrate the behavior of the DataTableReader.
DataTable table = new DataTable ();

Create two columns, ID and Name.
DataColumn idcolumn = table. Columns.Add ("ID", typeof (int));
Table. Columns.Add ("Name", typeof (String));

Set the ID column as the primary key column.
Table. PrimaryKey = new datacolumn[] {idcolumn};

Table. Rows.Add (New object[] {1, "Mary"});
Table. Rows.Add (New object[] {2, "Andy"});
Table. Rows.Add (New object[] {3, "Peter"});
Table. Rows.Add (New object[] {4, "Russ"});
return table;
}

private static void PrintColumns (DataTableReader reader)
{
Loop through all of the rows in the DataTableReader
while (reader. Read ())
{
for (int i = 0; i < reader. FieldCount; i++)
{
Console.Write (Reader[i] + "");
}
Console.WriteLine ();
}
}

Binary serialization for the DataSet

About this linkcd has written a performance test article:. Net 2.0 Performance Comparison of data container: Binary Serialize Dataset vs Custom Classes

DataTable as a stand-alone Object

Many methods of the previous dataset can now be used directly using the DataTable

Create a DataTable from a DataView

Now you can return a DataTable from DataView, the two are basically the same, and of course you can also have a selective return, such as return distinct rows

New DataTable Loading Capabilities

DataTables and Datasets now offer a new load method that can load data streams in DataReader into a DataTable, but you can also make some choices about how to load.

These are some of the features of ado.net2.0 that you use. NET2.0 for development, you can use these features.

What's more exciting is the ado.net3.0 features.

An article introduces some of the features of the ado.net3.0 Augut CTP:

The Ado.net Entity Framework

The Entity Data Model (EDM), the entity database models, developers can design data models at a higher level of abstraction
A very bull client-views/mapping engine that maps (map to and form) storage structure (store schemas)
Full support for using Entity SQL with LINQ (this thing now appears to be very high frequency oh, also quite fun of a dongdong) query EDM schemas
.....
LINQ (August CTP):

LINQ to Entities: Using LINQ query EDM schemas
LINQ to DataSet: LINQ query to one or more DataTable
are very much looking forward to the technology, Enjoy it! :)



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.