Copying records

Posted on 2006-05-04
Last Modified: 2010-04-23
I have a record that I need to duplicate except for a couple fields.  The record has about 20 fields, I need to copy it in full except for 2 fields.  I need to modify those fields to values the user inputs.  Anyone have a suggestion on how to do this?

Question by:Gawron3
    LVL 62

    Expert Comment

    by:Fernando Soto
    Need more info.
    The record, is it from a file?
    Is it going to be written back out to a file?
    How are the  fields separated?
    Are the fields fixed width?
    VS .Net 2003 or .Net 2005?

    Author Comment

    THe table is an access table with about 20 fields in it.  THe record I want to copy will be a record in that same table, but I will need to change a couple fields on the new record.  It is with .net 2003.
    LVL 34

    Accepted Solution

    Here's the basic technique

            Dim newdr As DataRow = MyTable.NewRow
            Dim olddr As DataRow = MyTable.Rows(<index of row to copy>)
            newdr.ItemArray = olddr.ItemArray
            'you can make changes to values in new row programmatically here
            'or the user can do so after this if the new record is then displayed in bound controls

    You can modify it - e.g. only to copy over some of the items - by replacing this line

            newdr.ItemArray = olddr.ItemArray

    with something on the lines of

            newdr(<index of item to copy>) = olddr(<index of item to copy>)

    repeated for each item that you want copied


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video discusses moving either the default database or any database to a new volume.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now