DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 25 Jul 2007 15:52:51 -0400,    posted on: microsoft.public.dotnet.framework.adonet        back       

Thread Index
  1    lucius am
          2    Benny Skjold Tordrup
          3    (WenYuan Wang [MSFT])
          4    (WenYuan Wang [MSFT])


Merge DataRow Items?   
I have a DataTable with one row and I did a Merge() from another
DataTable and now I have two rows. How can I get the rows to be a
single row (assuming row 0 is the "dominant" one).

Thanks.
Date:Wed, 25 Jul 2007 15:52:51 -0400   Author:  

Re: Merge DataRow Items?   
Do you have a primary key column defined in the DataTable?


"lucius" <lucius@newsgroup.nospam> skrev i en meddelelse 
news:qeafa3tj2aqtm5l42mkgp8he6g1n3m9omi@4ax.com...

>
> I have a DataTable with one row and I did a Merge() from another
> DataTable and now I have two rows. How can I get the rows to be a
> single row (assuming row 0 is the "dominant" one).
>
> Thanks.
> 
Date:Thu, 26 Jul 2007 09:09:58 +0200   Author:  

RE: Merge DataRow Items?   
Hello Lucius,
Thanks for Benny's response.

DataTable.Merge() method merge two tables by Primary key.

In your case, the table that has to be merged needs the same primary key as 
the destination table.
For example:

            System.Data.DataTable dt1 = new System.Data.DataTable();
            dt1.Columns.Add("c1");
            dt1.Columns.Add("c2");
            dt1.PrimaryKey = new System.Data.DataColumn[] { dt1.Columns[0]};
            dt1.Rows.Add(new object[] { 1, 1 });
            dt1.Rows.Add(new object[] { 2, 2 });
            dt1.Rows.Add(new object[] { 3, 3 });

            System.Data.DataTable dt2 = new System.Data.DataTable();
            dt2.Columns.Add("c1");
            dt2.Columns.Add("c2");
            dt2.PrimaryKey = new System.Data.DataColumn[] { dt2.Columns[0] 
};
            dt2.Rows.Add(new object[] { 1, 4 });
            dt2.Rows.Add(new object[] { 2, 5 });
            dt2.Rows.Add(new object[] { 3, 6 });

            dt1.Merge(dt2);

Result: dt1
C1, C2
1,4
2,5
3,6

Hope this helps. If there is anything unclear, please feel free to update 
here. I'm glad to assit you.
Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Thu, 26 Jul 2007 09:21:50 GMT   Author:  

RE: Merge DataRow Items?   
Hello Lucius,

This is Wen Yuan again. I haven't heard from you about a couple of days.
I just want to check if there is anything we can help with.
Have you resolved the issue so far?
Please feel free to update here if you have any concern. We are glad to 
assist you.

Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Mon, 30 Jul 2007 11:10:22 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us