日期:2014-05-17 浏览次数:20442 次
/// <summary>
/// SqlDataReader批量添加(没有事务)
/// </summary>
/// <param name="Reader">数据源</param>
/// <param name="Mapping">定义数据源和目标源列的关系集合</param>
/// <param name="DestinationTableName">目标表</param>
public static void MySqlBulkCopy(SqlDataReader Reader, SqlBulkCopyColumnMapping[] Mapping, string DestinationTableName)
{
using(SqlBulkCopy copy=new SqlBulkCopy(ConnectionString))
{
copy.DestinationTableName = DestinationTableName;//设置要添加的表名
if(Mapping!=null)
{
//如果有匹配
foreach (SqlBulkCopyColumnMapping Mapp in Mapping)
{
copy.ColumnMappings.Add(Mapp);
}
}
try
{
copy.WriteToServer(Reader);//批量添加
}
finally