Solved

Is it possible to update a DataTable existing rows?

Posted on 2014-10-10
2
97 Views
Last Modified: 2014-10-11
I'm using a DataTable to handle detail records. The flow of logic is that a user retrieves a 1 Header Record and 1 or more Detail Records from the Database. The Detail Records are loaded into a DataGridView. Each time the user selects a Detail Record from the DGV, it loads the data into various controls on the Windows Form. What I would like to do is simply assign each DataColumn to each control and then just Update or Refresh the DataRow and then the DataTable. I'm pretty sure this can be done but not exactly sure how to execute it.

Thanks!
0
Comment
Question by:BlakeMcKenna
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40374192
Yes it can be done.


When they click the save button you would have to:

1)  Find the DataRow in the DataTable:
Dim dr as DataRow
' find the specific row.  I'm matching the ID column in the datatable to a label id which you need to populate so you can keep track yourself.

dr = myDataTable.Rows.OfType(DataRow).Where(Function(r) r("ID") = lblID.Text).Single()

Open in new window


2) edit the row:
dr.BeginEdit()
dr("Field1") = txt1.Text
dr("field2") = ddl1.SelectedValue
'etc
dr.EndEdit

Open in new window


Note that this saves it to the datatable.  You would have to push this back to the database using a dataadapter or looping over the rows.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40374938
Thanks Kyle...that did the trick!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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