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
Solved

Is it possible to update a DataTable existing rows?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 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