copying the column values of a Datatable into another data table in vb.net

Discussion in 'ASP .Net' started by Balu, Jan 2, 2006.

  1. Balu

    Balu Guest

    Hi All,

    Can anybody tell me how to copy one column of a data table to another data
    table.

    Example:I have 2 data tables say dt1,dt2.
    Here,i wanna copy only the 1st column values of dt1 into the 1st column of
    dt2.
    Its an urgent work for me.So,anyone of you can give me a solution to this.

    Regards,
    Mahalakshmi.
    Balu, Jan 2, 2006
    #1
    1. Advertising

  2. Hi Mahalakshmi,

    Does the Copy() method that Christopher Reed suggested in your other thread
    work for you?

    > tblTwo = tblOne.Copy();


    --
    Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    www.cindywinegarden.com


    "Balu" <> wrote in message
    news:OuE1%...
    > Hi All,
    >
    > Can anybody tell me how to copy one column of a data table to another data
    > table.
    >
    > Example:I have 2 data tables say dt1,dt2.
    > Here,i wanna copy only the 1st column values of dt1 into the 1st column of
    > dt2.
    > Its an urgent work for me.So,anyone of you can give me a solution to this.
    >
    > Regards,
    > Mahalakshmi.
    >
    Cindy Winegarden, Jan 2, 2006
    #2
    1. Advertising

  3. Balu

    Balu Guest

    Hi,
    Its working fine.But,i wanna copy only one column of a table not the
    entire data.
    But,the statement .....
    tblTwo=tblOne.Copy()
    copies the entire data,i.e.,all column values into another table.
    Can anybody give a solution for it?

    Regards,
    Maha.
    "Cindy Winegarden" <> wrote in message
    news:...
    > Hi Mahalakshmi,
    >
    > Does the Copy() method that Christopher Reed suggested in your other
    > thread work for you?
    >
    >> tblTwo = tblOne.Copy();

    >
    > --
    > Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    > www.cindywinegarden.com
    >
    >
    > "Balu" <> wrote in message
    > news:OuE1%...
    >> Hi All,
    >>
    >> Can anybody tell me how to copy one column of a data table to another
    >> data table.
    >>
    >> Example:I have 2 data tables say dt1,dt2.
    >> Here,i wanna copy only the 1st column values of dt1 into the 1st column
    >> of dt2.
    >> Its an urgent work for me.So,anyone of you can give me a solution to
    >> this.
    >>
    >> Regards,
    >> Mahalakshmi.
    >>

    >
    >
    Balu, Jan 3, 2006
    #3
  4. Hi Balu,

    Are you saying that you want to add a new column to a table and populate it
    or populate a column that's already there but is empty? To do that you'll
    need to use an update statement and connect the record in the source table
    to the record in the target table via a primary key. It's not as easy as
    copying/pasting a column in Excel, for example.

    In a SQL Server script this would be something like:

    Alter Table Target Add NewColumn Integer
    Go
    Update Target
    Set Target.NewColumn =
    (Select Source.OldColumn From Source
    Where Source.PrimaryKey = Target.PrimaryKey)

    --
    Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    www.cindywinegarden.com


    "Balu" <> wrote in message
    news:...
    > Hi,
    > Its working fine.But,i wanna copy only one column of a table not the
    > entire data.
    > But,the statement .....
    > tblTwo=tblOne.Copy()
    > copies the entire data,i.e.,all column values into another table.
    > Can anybody give a solution for it?
    >
    > Regards,
    > Maha.
    > "Cindy Winegarden" <> wrote in message
    > news:...
    >> Hi Mahalakshmi,
    >>
    >> Does the Copy() method that Christopher Reed suggested in your other
    >> thread work for you?
    >>
    >>> tblTwo = tblOne.Copy();

    >>
    >> --
    >> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    >> www.cindywinegarden.com
    >>
    >>
    >> "Balu" <> wrote in message
    >> news:OuE1%...
    >>> Hi All,
    >>>
    >>> Can anybody tell me how to copy one column of a data table to another
    >>> data table.
    >>>
    >>> Example:I have 2 data tables say dt1,dt2.
    >>> Here,i wanna copy only the 1st column values of dt1 into the 1st column
    >>> of dt2.
    >>> Its an urgent work for me.So,anyone of you can give me a solution to
    >>> this.
    >>>
    >>> Regards,
    >>> Mahalakshmi.
    >>>

    >>
    >>

    >
    >
    Cindy Winegarden, Jan 4, 2006
    #4
  5. Balu

    Balu Guest

    Copying data of one data table to another data table.

    Hi Cindy,
    Thanks for ur reply.
    But,actually what i want is, to copy a single column of the data table say
    'dt1' to a column in another data table say 'dt2'.
    I am using dt2=dt1.
    But,its copying the entire data of data table 'dt1' to data table 'dt2'.
    What i want is to copy only the 1st column data of dt1 to 1st column of dt2.
    If you have any idea?Please do reply....waiting for ur reply.

    Regards,
    Maha.
    "Cindy Winegarden" <> wrote in message
    news:...
    > Hi Balu,
    >
    > Are you saying that you want to add a new column to a table and populate
    > it or populate a column that's already there but is empty? To do that
    > you'll need to use an update statement and connect the record in the
    > source table to the record in the target table via a primary key. It's not
    > as easy as copying/pasting a column in Excel, for example.
    >
    > In a SQL Server script this would be something like:
    >
    > Alter Table Target Add NewColumn Integer
    > Go
    > Update Target
    > Set Target.NewColumn =
    > (Select Source.OldColumn From Source
    > Where Source.PrimaryKey = Target.PrimaryKey)
    >
    > --
    > Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    > www.cindywinegarden.com
    >
    >
    > "Balu" <> wrote in message
    > news:...
    >> Hi,
    >> Its working fine.But,i wanna copy only one column of a table not the
    >> entire data.
    >> But,the statement .....
    >> tblTwo=tblOne.Copy()
    >> copies the entire data,i.e.,all column values into another table.
    >> Can anybody give a solution for it?
    >>
    >> Regards,
    >> Maha.
    >> "Cindy Winegarden" <> wrote in message
    >> news:...
    >>> Hi Mahalakshmi,
    >>>
    >>> Does the Copy() method that Christopher Reed suggested in your other
    >>> thread work for you?
    >>>
    >>>> tblTwo = tblOne.Copy();
    >>>
    >>> --
    >>> Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    >>> www.cindywinegarden.com
    >>>
    >>>
    >>> "Balu" <> wrote in message
    >>> news:OuE1%...
    >>>> Hi All,
    >>>>
    >>>> Can anybody tell me how to copy one column of a data table to another
    >>>> data table.
    >>>>
    >>>> Example:I have 2 data tables say dt1,dt2.
    >>>> Here,i wanna copy only the 1st column values of dt1 into the 1st column
    >>>> of dt2.
    >>>> Its an urgent work for me.So,anyone of you can give me a solution to
    >>>> this.
    >>>>
    >>>> Regards,
    >>>> Mahalakshmi.
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Balu, Jan 6, 2006
    #5
  6. Re: Copying data of one data table to another data table.

    As I posted above, that's exactly what the code I posted above does.

    --
    Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
    www.cindywinegarden.com


    "Balu" <> wrote in message
    news:O6$...
    > ... copy a single column of the data table say 'dt1' to a column in
    > another data table say 'dt2'.
    Cindy Winegarden, Jan 6, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,315
    Kevin Spencer
    Aug 15, 2003
  2. Nedu N
    Replies:
    2
    Views:
    2,142
  3. jg
    Replies:
    1
    Views:
    713
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  4. Ersin Gençtürk
    Replies:
    1
    Views:
    3,464
    Ersin Gençtürk
    Oct 6, 2004
  5. Nathan Sokalski

    Copying DataRows to another DataTable

    Nathan Sokalski, Nov 19, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    34,183
    jagdish.bhoir
    May 21, 2009
Loading...

Share This Page