利用DataTable快速批量导数据

 DataSet ds = new DataSet();
            using (SqlConnection conn = new SqlConnection(@"data source=.\sqlxu;initial catalog=NationalUnion20140717;persist security info=True;user id=sa;password=101;MultipleActiveResultSets=True"))
            {
                SqlDataAdapter da = new SqlDataAdapter("select * from [dbo].[ProductType]", conn);
                da.Fill(ds);
            }

            string connTest = @"data source=10.57.40.184;initial catalog=NationalUnion;persist security info=True;user id=NationalUsers;password=P@ssw0rd;MultipleActiveResultSets=True";
            //using (SqlConnection connTest = new SqlConnection())
            //{
            SqlBulkCopy sbc = new SqlBulkCopy(connTest, SqlBulkCopyOptions.UseInternalTransaction);
            sbc.DestinationTableName = "[dbo].[ProductType]";
            sbc.BulkCopyTimeout = 0;
            sbc.WriteToServer(ds.Tables[0]);

你可能感兴趣的:(Datatable)