ADO.NET 2.0 大批量数据操作和多个动态的结果集
2005-11-23 16:46
369 查看
Csdn dotnet blog 专家群 高海东
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.
看更多.net技术文章 到 Csdn dotnet 频道。
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.
看更多.net技术文章 到 Csdn dotnet 频道。
相关文章推荐
- ADO.NET 2.0 大批量数据操作和多个动态的结果集
- ADO.NET 2.0 大批量数据操作和多个动态的结果集
- ADO.NET 2.0 大批量数据操作和多个动态的结果集
- ADO.NET 2.0 大批量数据操作和多个动态的结果集
- ADO.NET 2.0 大批量数据操作和多个动态的结果集
- ADO.NET 2.0 大批量数据操作和多个动态的结果集[转]
- ADO.NET2.0批量数据操作和多动态结果集
- ADO.NET 2.0批量数据操作和多动态结果集
- ADO.NET中的多数据表操作浅析—修改
- 用多活动结果集优化ADO.NET2.0数据连接
- ASP.NET 2.0 中的数据操作:: 使用 GridView 和DetailView实现的主/从报表
- 在ASP.NET 2.0中操作数据之四十:自定义DataList编辑界面
- 在ASP.NET 2.0中操作数据之三十六:在DataList里编辑和删除数据概述
- ADO.NET大批量更新数据
- 3.设计数据存储策略:ADO.NET 2.0及其他
- 在ASP.NET 2.0中操作数据之四十三:DataList和Repeater数据排序(二)
- ADO.NET中数据操作浅述
- 在ASP.NET 2.0中操作数据之四十六:使用SqlDataSource控件检索数据
- 使用ADO.NET查询和操作数据
- asp.net学习总结——ADO.net(对Sql Server进行操作的数据访问类)