{"id":1419,"date":"2011-02-06T09:16:56","date_gmt":"2011-02-06T03:46:56","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=1419"},"modified":"2011-02-06T09:16:56","modified_gmt":"2011-02-06T03:46:56","slug":"this-row-already-belongs-to-another-table-error","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/this-row-already-belongs-to-another-table-error\/","title":{"rendered":"This row already belongs to another table &#8211; Error"},"content":{"rendered":"<p>A beginner in C#, most of the time get error <strong>&#8220;This row already belongs to another table<\/strong>&#8221; while adding Row from one <strong>DataTable <\/strong>to another <strong>DataTable<\/strong>.<\/p>\n<p>The reason of this error is that, we cannot add row of one table into another directly, we have to use the API of C# as shown below:<\/p>\n<p><!--more--><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ This example generates the error\n\n\/\/ ds is a dataset that has previously been populated\n\nDataTable dt1 = ds.Tables&#x5B;0];\n\nDataTable dt2 = new DataTable();\n\nforeach(DataRow row in dt1.Rows){\n\n    if(row&#x5B;&quot;Column1&quot;] == 10){\n\n        \/\/ This line generates the error...\n        dt2.Rows.Add(row);\n\n    }\n\n}\n<\/pre>\n<p>The correct way to copy the row is :<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ This example achieves the copy\n\n\/\/ ds is a dataset that has previously been populated\n\nDataTable dt1 = ds.Tables&#x5B;0];\n\nDataTable dt2 = new DataTable();\n\ndt2 = dt1.Clone();\n\nforeach(DataRow row in dt1.Rows){\n\n    if(row&#x5B;&quot;Column1&quot;] == 10){\n\n        \/\/ Import the Row into dt2 from dt1\n        dt2.ImportRow(row);\n\n    }\n\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This row already belongs to another table &#8211; Error resolved<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[22,5],"tags":[51],"class_list":["post-1419","post","type-post","status-publish","format-standard","hentry","category-csharp","category-microsoft","tag-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":608,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/selecting-and-sorting-in-datatable-asp-net-c\/","url_meta":{"origin":1419,"position":0},"title":"Selecting and Sorting in DataTable &#8211; ASP.net C#","author":"Jitendra","date":"July 7, 2010","format":false,"excerpt":"Demonstrates that how to select and sort the Datatable in ASP.Net , C#","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Sorting and Selecting DataTable in ASP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/07\/Sorting-and-Selecting-DataTable-in-ASP-300x223.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":227,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/datagrid-example-sorting-part-2\/","url_meta":{"origin":1419,"position":1},"title":"DataGrid Sorting and Paging Example \u2013 Part 2","author":"Jitendra","date":"May 18, 2010","format":false,"excerpt":"For Part 1, visit This URL\u00a0https:\/\/jitendrazaa.com\/blog\/?p=191 In this part, i will show that how to Sort the Datagrid Component of ASP.NET. To sort Datagrid, we will need DataView and then assign Dataview as datasource to our Grid control. We will need to change our code of Part 1. Previously, we\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Sorting1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":7101,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/implement-infinite-scrolling-for-lightning-data-table\/","url_meta":{"origin":1419,"position":2},"title":"Implement Infinite Scrolling for lightning-datatable","author":"Jitendra","date":"June 10, 2020","format":false,"excerpt":"When to use wire vs Imperative approach to call Apex in Lightning Web Component","rel":"","context":"In &quot;Lightning Web Components&quot;","block_context":{"text":"Lightning Web Components","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/lightning-web-components\/"},"img":{"alt_text":"Salesforce Lightning Datatable Infinite Scrolling","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/06\/Salesforce-Lightning-Datatable-Infinite-Scrolling-e1624579111169.png?fit=700%2C385&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/06\/Salesforce-Lightning-Datatable-Infinite-Scrolling-e1624579111169.png?fit=700%2C385&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/06\/Salesforce-Lightning-Datatable-Infinite-Scrolling-e1624579111169.png?fit=700%2C385&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2020\/06\/Salesforce-Lightning-Datatable-Infinite-Scrolling-e1624579111169.png?fit=700%2C385&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":6419,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/introduction-to-lightning-test-services-with-jasmine\/","url_meta":{"origin":1419,"position":3},"title":"Introduction to Lightning Test Services with Jasmine","author":"Jitendra","date":"March 10, 2018","format":false,"excerpt":"Complete Source code and video of using Lightning Datatable Component and Jasmine in Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Lightning Testing Service (LTS)","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2018\/03\/Lightning-Testing-Service-LTS.png?fit=1200%2C433&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1385,"url":"https:\/\/www.jitendrazaa.com\/blog\/sql\/sqlserver\/difference-in-ado-and-ado-net\/","url_meta":{"origin":1419,"position":4},"title":"Difference in ADO and ADO.Net &#8211; Interview Question","author":"Jitendra","date":"December 5, 2010","format":false,"excerpt":"Basic comparison between ADO and ADO.Net component in .Net Framework","rel":"","context":"In &quot;c#&quot;","block_context":{"text":"c#","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/csharp\/"},"img":{"alt_text":"ADO.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/12\/ADO.Net_.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1527,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/ajax-based-multiselect-jquery-autocomplete-control-in-asp-net\/","url_meta":{"origin":1419,"position":5},"title":"Ajax Based Multiselect JQuery Autocomplete Control in ASP.Net","author":"Jitendra","date":"February 19, 2011","format":false,"excerpt":"Tutorial on creating Ajax Based Multiselect JQuery Autocomplete User Control in ASP.Net","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Ajax Based Multiselect JQuery Autocomplete Control in ASP.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Ajax-Based-Multiselect-JQuery-Autocomplete-Control-in-ASP.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=1419"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/1419\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=1419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=1419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=1419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}