1.大 批量 数据 操作 可以利用SqlBulkCopy类快速写入大 批量 数据 ,针对SQL Server的优化,可以写入DataRow 数据 ,DataTable,DataReader WriteToServer(DataTable)写入 数据 表 WriteToServer(DataRow[])批次写入 数据 行 WriteToServer(DataTable ,
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]);
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.
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号