Solved

Is it possible to update a DataTable existing rows?

Posted on 2014-10-10
2
94 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 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
Thanks Kyle...that did the trick!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

15 Experts available now in Live!

Get 1:1 Help Now