Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6699303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:40:46+00:00 2026-05-26T06:40:46+00:00

I Have two datatables as follows Table1 ——————————– Id | Batch | Qty —————————–

  • 0

I Have two datatables as follows

Table1
--------------------------------
Id     | Batch  | Qty
-----------------------------
1         A1       5
2         A2       5
3         A3       5
4         A4       5


Table2
--------------------------------
Id     | Batch  | Qty
-----------------------------
1         A1       6
2         A2       6
3         A3       6
5         A5       10

Expected result
--------------------------------
Id     | Batch  | Qty
-----------------------------
1         A1       6 (Qty updated)
2         A2       6 (Qty updated)
3         A3       6 (Qty updated)
4         A4       5 (remains as same)
5         A5       10 (row in table 2)

How can i achieve this in c#. If anybody knows this data table operation please share..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:40:47+00:00Added an answer on May 26, 2026 at 6:40 am

    try something like this, this is an example how to merge two datatables…

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    
    using System.Data; 
    
    namespace ConsoleApplication1 
    { 
      class Program 
      { 
         static void Main(string[] args) 
         { 
              DataColumn col; 
              DataTable table1 = new DataTable(); 
              table1.PrimaryKey = new DataColumn[] { 
              col = table1.Columns.Add("slot_id") 
               }; 
              col.DataType = typeof(int); 
              col.Unique = true; 
              col = table1.Columns.Add("appointment_time"); 
              col = table1.Columns.Add("patient_name"); 
              col = table1.Columns.Add("patient_doctor"); 
    
              table1.Rows.Add(1, "0900", "George Michael"); 
    
              DataTable table2 = new DataTable(); 
              table2.PrimaryKey = new DataColumn[] { 
              col = table2.Columns.Add("slot_id") 
               }; 
              col.DataType = typeof(int); 
              col.Unique = true; 
             col = table2.Columns.Add("appointment_time"); 
    
              table2.Rows.Add(1, "0900"); 
              table2.Rows.Add(2, "1000"); 
              table2.Rows.Add(3, "1100"); 
              table2.Rows.Add(4, "1200"); 
    
             DataTable merged = new DataTable(); 
            merged.Merge(table1); 
            merged.Merge(table2); 
    
            foreach (DataColumn dc in merged.Columns) 
            Console.Write(dc.ColumnName + "\t"); 
            Console.WriteLine(); 
    
           foreach (DataRow dr in merged.Rows) 
           { 
                foreach (DataColumn dc in merged.Columns) 
                Console.Write(dr[dc.ColumnName] + "\t"); 
                Console.WriteLine(); 
           } 
           Console.WriteLine(); 
    
           Console.Write("Press any key to continue . . . "); 
           Console.ReadKey(true); 
           Console.WriteLine(); 
        } 
      } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two .NET DataTables populated as follows, where ID is the primary
I have two dataTables as follows 1) dtExistingZipCodeInDB (data from database) 2) dtCSVExcelSource (data
I have two mirrored datatables (same structure with two primary keys) : DataTable_A --->
I have two DataTables, A and B , produced from CSV files. I need
I have two datatables. One is to display names. Another contains three <h:selectOneMenu> .
I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
I have two DataTables one is Primary Table and the rest is a sub
Let's say I have two DataTables DT1 and DT2 with a single row. DT1
i have windows application in which i am constructing dataset with two datatables one
I have two datatables dt1 and dt2 i copied dt2 into dt1 and clear

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.