Solved

Updating a DataTable in Memory?

Posted on 2009-04-13
1
276 Views
Last Modified: 2012-06-27
Experts,

All the lit I've read on updating a bound DataTable talk about mapping the "UpdateMethod" property to a method that will take parameters from the grid and then updating the actual database table.  In other words, the update goes right to the table instead of to the DataTable object.  I don't want to write to the database when the user is adding quantities to items in his/her order.  I want to update in memory and then once the user is finished, update that object to a database.

Is this possible?
0
Comment
Question by:NigelRocks
1 Comment
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
ID: 24134516
Yes. First, you need to get the DataRow to be updated. For this you need to have some kind of key or identification. An example:
DataRow[] rows = dtTable.Select("ID = 10");
DataRow rowToUpdate = null;
if ((rows != null) && (rows.Count > 0))
  rowToUpdate = rows[0];

OR, if you have initialised the PrimaryKey property of that DataTable:

DataRow rowToUpdate = dtTable.Rows.Find(10);

Second, update the columns accordingly:
rowToUpdate["GivenName"] = "John";
rowToUpdate["FamilyName"] = "Doe";
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now