覺得很多人在寫關于asp.net2.0的東東,很少有人寫關于ADO.NET2.0的新特性。查找了一下MSDN,給大家介紹幾點好了。(如果需要察看所有ADO.NET2.0的新特性,請查看
http://msdn2.microsoft.com/en-us/library/ex6y04yf.aspx)
Server Enumeration
用來枚舉活動狀態的SQL Server實例,版本需要在SQL2000及更新版本。使用的是SqlDataSourceEnumerator類
可以參考以下示例代碼:
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
新的DataTableReader類可以說是一個DataSet或者DataTable,的一個或者多個的read-only, forward-only的結果集。需要說明的是,DataTable返回的DataTableReader不包含被標記為deleted的行。
示例:
private static void TestCreateDataReader(DataTable dt)
{
// Given a DataTable, retrieve a DataTableReader
// allowing access to all the tables' data:
using (DataTableReader reader = dt.CreateDataReader())
{
do
{
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 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
關于這點linkcd已經寫過一篇性能測試的文章:.Net 2.0 下Data Container性能比較: Binary Serialize Dataset vs Custom Classes
DataTable as a Stand-Alone Object
很多以前DataSet的方法,現在可以用DataTable直接使用了
Create a DataTable from a DataView
現在可以從DataView返回一個DataTable了,兩者基本是一樣的,當然你也可以有選擇性的返回,比如說返回distinct rows
New DataTable Loading Capabilities
DataTables跟DataSets現在提供一個新的Load方法,可以直接把DataReader中的數據流載入到DataTable中,當然你也可以對如何Load做一些選擇。
以上是ADO.NET2.0的一些特性,你使用.NET2.0進行開發,就可以使用這些特性。
更激動人心的在于ADO.NET3.0的一些特性.
有文章介紹了一些ADO.NET3.0 AUGUT CTP的一些特性:
The ADO.NET Entity Framework
The Entity Data Model (EDM),實體數據模型,開發者可以以更高的抽象層次來設計數據模型
一個很牛的client-views/mapping引擎,用來映射(map to and form)存儲結構(store schemas )
完全支持使用Entity SQL跟LINQ( 這東西現在出現頻率還挺高的哦,也挺好玩的一個東東)查詢EDM schemas
.....
LINQ(AUGUST CTP):
LINQ to Entities: 使用LINQ查詢EDM schemas
LINQ to DataSet: 對一個或者多個DataTable進行LINQ查詢
都是很期待的技術,Enjoy it?。海?/P>
http://www.49028c.com/wdxinren/archive/2006/09/04/494260.html
新聞熱點
疑難解答