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 7278351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:51:46+00:00 2026-05-28T22:51:46+00:00

I have two datatable , first contain DataTable dtMaterialStatement = new DataTable(); dtMaterialStatement.Columns.Add(new DataColumn(MaterialNo,

  • 0

I have two datatable , first contain

 DataTable  dtMaterialStatement = new DataTable();
                    dtMaterialStatement.Columns.Add(new DataColumn("MaterialNo", Type.GetType("System.String")));
                    dtMaterialStatement.Columns.Add(new DataColumn("MaterialId", Type.GetType("System.String")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Qty", Type.GetType("System.Double")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Unit", Type.GetType("System.String")));
                    dtMaterialStatement.Columns.Add(new DataColumn("SinglePrice", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("PricePerPack", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("UnitsPerPack", Type.GetType("System.String")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Discount1", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Discount2", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Discount3", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("SalesPrice", Type.GetType("System.Decimal")));
                    dtMaterialStatement.Columns.Add(new DataColumn("Exist", Type.GetType("System.Boolean")));

Second contain:-

"MaterialNo"
  Qty
 "Unit"
 "SinglePrice"
 "PricePerPack"
 "UnitsPerPack"
 "Discount1"
  "Discount2"
 "Discount3"
 "SalesPrice"

and come extra column ,

I want to merge both table , if MaterialNo of first tabel is same with second table MaterialNo column , then take common column field value from second table to update value of first value corresponding columns.
else insert a new row in first table with using column of table first but taking value from second table.

  • 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-28T22:51:47+00:00Added an answer on May 28, 2026 at 10:51 pm
    1. Use this one to extract a new datatables that only contains differences http://kodesharp.blogspot.com/2007/12/c-compare-2-datatables-and-return-3rd.html

    2. Then use foreach or for loop to manually extract the differenes into array. Then have it repumped into the datatable

    Something like this:

    DataTable dt = CompareDataTables(dt1, dt2);
    
    ArrayList Errors = new ArrayList();
    
    for (int i = 0; i < d.Columns.Count; i++)
    {
        for (int j = 0; j < d.Rows.Count; j++)
        {
            if (dt1.Rows[j][i].ToString() != dt2.Rows[j][i].ToString())
                {
                    Errors.Add(j);
                    Errors.Add(i);
                    Errors.Add(dt1.Rows[j][i].ToString());
                    Errors.Add(dt2.Rows[j][i].ToString());
                }
         }
     }
    
    DataTable dtFinal = dt;
    
    for (int i = 0; i < Errors.Count; i += 4)
    {
        int ak = Int32.Parse(Errors[i].ToString());
        int bk = Int32.Parse(Errors[i + 1].ToString());
        dtFinal.Rows[ak][bk] = Errors[i + 2].ToString() + "/" + Errors[i + 3].ToString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two DataTables. First is DataTable NameAddressPhones = new DataTable(); with Three columns
In .net objects like DataTable when you have two grids(Master and Detail) and add
I'm using Visual Studio 2005 and have a DataTable with two columns and some
I have two DataTable [System.Data] .One contains three rows id,name,date and another contains id
I have two datatable, while adding rows in second datatable, I want to first
I have added two datatable using persistent class in Devexpess XPQuery<me_employee> EmployeeQuery = new
I have a dropdown. I need to bind with two field of datatable value
I have a task where I need to translate a DataTable to a two-dimensional
I have two pages. Search page is the first page that takes user inputs.
I have two methods that do the same thing. The first one makes performance

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.