国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ADO.NET2.0跟ADO.NET3.0的一些新特性簡要介紹

2024-07-10 13:04:45
字體:
來源:轉載
供稿:網友

覺得很多人在寫關于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!:)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绩溪县| 比如县| 界首市| 临朐县| 杂多县| 潞西市| 深州市| 霍城县| 静安区| 库伦旗| 大邑县| 历史| 错那县| 墨脱县| 桦甸市| 西城区| 东明县| 大姚县| 高安市| 沧源| 枣庄市| 商河县| 峨眉山市| 克什克腾旗| 延庆县| 大埔县| 临安市| 新营市| 鹤庆县| 淳化县| 龙井市| 新干县| 宜城市| 沙湾县| 丘北县| 分宜县| 常宁市| 建宁县| 濉溪县| 东兰县| 凤台县|