软件频道>开发者网络>微软开发专栏>ASP.NETC#VB.NETVC.NET技术专题XML|软件频道产品中心群乐下载群乐:大家耍QQ
您现在的位置: 天极网 > 开发频道 > 微软开发专栏 > ADO.NET 2.0批量数据操作和多动态结果集
全文

ADO.NET 2.0批量数据操作和多动态结果集

2005-11-01 10:10作者:高海东出处:博客网责任编辑:方舟
  1.大批量数据操作

  可以利用SqlBulkCopy类快速写入大批量数据,针对SQL Server的优化,可以写入DataRow数据,DataTable,DataReader

  WriteToServer(DataTable)写入数据表

  WriteToServer(DataRow[])批次写入数据行

  WriteToServer(DataTable ,DataRowState)按行状态写入数据库表

  WriteToServer(IDataReader)写入DataReader对象

  string connstr = "server=(local);database=northwind;integrated security=true;async=true";
            
// Fill up a DataSet
            DataSet ds = new DataSet();
            SqlConnection conn 
= new SqlConnection(connstr);
            SqlDataAdapter dadp 
= new SqlDataAdapter("select * from customers", conn);
            dadp.Fill(ds);
            
// Copy the Data to SqlServer
            SqlBulkCopy bcp = new SqlBulkCopy(connstr);
            bcp.DestinationTableName 
= "customers1";
            bcp.WriteToServer(ds.Tables[
0]);

  2.多个动态的结果集

  Multiple Active Result Sets(MARS)

  这个只能在SQL Server 2005中使用

  可以在一个Command对象上同时打开多个DataReader

 string connstr = "server=(local);database=northwind;integrated security=true;async=true";
            SqlConnection conn 
= new SqlConnection(connstr);
            conn.Open();
            SqlCommand cmd1 
= new SqlCommand("select * from customers", conn);
            SqlCommand cmd2 
= new SqlCommand("select * from orders", conn);
            SqlDataReader rdr1 
= cmd1.ExecuteReader();
            
// next statement causes an error prior to SQL Server 2005
            SqlDataReader rdr2 = cmd2.ExecuteReader();
            
// now you can reader from rdr1 and rdr2 at the same time.

软件资讯·软件下载尽在天极软件

相关搜索:
关注此文读者还看过
关于我们|About us|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2009 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 渝ICP证B2-20030003号
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众