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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:51:14+00:00 2026-06-10T05:51:14+00:00

There is a datatable ( source ), and a copy of this datatable is

  • 0

There is a datatable ( source ), and a copy of this datatable is created ( copy ), and in this copy, some rows are modified in DataGridView.

After modification is over, A method is updating source datatable with modified rows in copy datatable.

DataTable source ;// it is population by database.

and its copy

DataTable copy = source.Copy(); // Here is the copy datatble.

The method is like :

public static void UpdateData(DataTable source, DataTable copy)
{
    foreach (DataRow row in copy.Rows)
    {
        if (row.RowState == DataRowState.Modified)
        {
            var relRow = source.Select("Id = '" + row["Id"] + "'");
            if (relRow.Any())
            {
                //relRow[0] = row; //This statement is not udating row in the source dataTable.
                foreach (var column in copy.Columns)
                {
                    relRow[0][column.ColumnName] = row[column.ColumnName];
                }
            }
        } 
        else if (row.RowState == DataRowState.Added)
        {
               //Performing some operations to for checking additional values. modiging 'row' with some relative data, and adding to source.
                source.Rows.Add(row.ItemArray);
        }       
    }

    return source;
}

when assigning a row object to datarows array’s first element like relRow[0] = row, it is not updating source datatable, but it is showing modified data while debuggin in relRow[0].

Column by column assignment reflecting changes in datatable.

So, The question is : Why relRow[0] = row not updating in source datatable?

Thanks.

  • 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-06-10T05:51:16+00:00Added an answer on June 10, 2026 at 5:51 am

    By writing relRow[0] = row;, you’re simply re-assigning the reference of relRow, modifying the 0th element of your local array. It isn’t actually changing the contents of the row in the table. Your code is the same as:

    DataRow[] localRows;
    // here, localRows will reference items in the source table. 
    // Below, you overwrite the reference.
    localRows = source.Select("Id = '" + row["Id"] + "'");
    if(localRows.Any())
    {
        //changes what reference the 0th element of the localRows array points to,
        // doesn't change anything about the datatable.
        // localRows[0] now points to the local variable row (i.e. the item from copy)
        localRows[0] = row; 
    }
    

    To modify the table, you can replace relRow[0] = row; with something that modifies the elements of relRow rather than its reference:

    for(var col = 0; col < source.Columns.Count; i++)
    {
        relRow[0][col] = row[col];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show in dataGridView some image. I have two components, dataGridView, dataTable
So I have this datagridview that is linked to a Binding source that is
Is there a convinient way of fetching a OData source into a System.Data.DataTable? The
Is there a C# DataTable equivalent in Java?
I am currently using YUI datatable, but it is buggy: http://developer.yahoo.com/yui/datatable/ Is there another
Is there a C# Library to generate a decision tree from a datatable and
Is there any maximum size for a cell of data in a DataTable (like
Is there a way to add a custom column to DataTable jQuery plugin, such
In a DataTable object, is there added overhead to looking up a column value
I am wondering if there is a simple way to allow a JQuery datatable

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.