SqlBulkCopy详细使用

    string connection = "数据库连接串";
            using (SqlConnection sqlconn = new SqlConnection(connection))
            {
                sqlconn.Open();
                try
                {
                    using (SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(sqlconn))
                    {
                        //内存表所对应的表列
                        SqlBulkCopyColumnMapping sm1 = new SqlBulkCopyColumnMapping("Name", "Name");
                        SqlBulkCopyColumnMapping sm2 = new SqlBulkCopyColumnMapping("ID", "ID");
                        sqlbulkcopy.ColumnMappings.Add(sm1);
                        sqlbulkcopy.ColumnMappings.Add(sm2);
                       //需要操作的数据库表名
                        sqlbulkcopy.DestinationTableName = "S";
                       //将内存表表写入
                        sqlbulkcopy.WriteToServer(ble);
                    }
                }
                catch (Exception ex)
                {
                }
            }


 
  
        

你可能感兴趣的:(C#)