日期:2014-05-18 浏览次数:20426 次
SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(connectionString); sqlBulkCopy.DestinationTableName = "Passport"; sqlBulkCopy.BatchSize = dataTable.Rows.Count; SqlConnection sqlConnection = new SqlConnection(connectionString); sqlConnection.Open(); if (dataTable!=null && dataTable.Rows.Count!=0) { sqlBulkCopy.WriteToServer(dataTable); } sqlBulkCopy.Close(); sqlConnection.Close();
------解决方案--------------------
DataTable数据批量写入数据库三种方法比较
------解决方案--------------------
SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.UseInternalTransaction); sqlbulkcopy.DestinationTableName = "Table_1";//数据库中的表名 sqlbulkcopy.WriteToServer(dataset.Tables[0]);