觉得很多人在写关于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!:)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix