Solved

Updating a DataTable in Memory?

Posted on 2009-04-13
1
277 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to read json value 2 53
Web Form VB.Net  import CSV 4 39
Media.Imaging 1 18
How to read text with RegEx... 2 11
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!

825 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