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.