Solved

Is it possible to update a DataTable existing rows?

Posted on 2014-10-10
2
100 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

733 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