473,394 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Modifying row in datatable??

VM
How can I modify a row in a datatable in a Windows form? For example, I want
to find the row where 'emplcode' equas '000001' and once I find it, change
the 'name' to 'John'. Then put the updated row back to the table.

Thanks.
Nov 16 '05 #1
2 4658
In article <Oc**************@TK2MSFTNGP10.phx.gbl>, vo******@yahoo.com
says...
How can I modify a row in a datatable in a Windows form? For example, I want
to find the row where 'emplcode' equas '000001' and once I find it, change
the 'name' to 'John'. Then put the updated row back to the table.


You can find the row with DataTable.Rows.Find().

Once found, simply update the data. You can then get the changed
DataTable via DataTable.GetChanges and pass that to a DataAdapter for
updating.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 16 '05 #2
VM
Never mind. I figured it out.

Basically, I retrieve the grid's datasource into a datatable:

DataTable DT_tempTable = (DataTable)dataGrid_auditAddress.DataSource;

do a query of of the table and put the result in a datarow collection:

DataRow[] row_1 = DT_tempTable.Select("col_row = '" + iRowNum.ToString() +
"'");
row_1[0]["col_mark"] = MARKED; //in this case, it always returns one row

Unfortunately, this automatically updates the datagrid also (which takes
ages if processing large amounts of rows), so you need to deattach the grid
datasource, modify the datatable, and reattach once again.


"VM" <vo******@yahoo.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
How can I modify a row in a datatable in a Windows form? For example, I want to find the row where 'emplcode' equas '000001' and once I find it, change
the 'name' to 'John'. Then put the updated row back to the table.

Thanks.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the...
2
by: MikeY | last post by:
Hi everyone, Using C#, Windows forms. I am trying to learn how to modify existing data with in MSDE table/fields. If anyone could help me out with my code, I would appreciate it. My code is as...
2
by: David Stephen | last post by:
I'd like to use a datagrid to display a result from a datatable but based on the data I'd like to display rows with merged cells is a new type of heading across a couple of standard cells or a...
6
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
1
by: Trev | last post by:
I would be very grateful if someone could help me with this. I have created a DataSet using Tables.Add(mDataSource), where mDataSource derives from database expressions. However, I now need to...
2
by: Nathan Sokalski | last post by:
I am trying to create a FormView controls in which I access and modify the the controls in the PagerTemplate programmatically. However, I continue to recieve the following error: Object...
4
by: sklett | last post by:
(I posted this in a databinding NG, but it's a VERY low traffic NG so I thought I would post here as well. I hope no one minds too much, if you do I'm sorry) I have a DGV that is bound to a...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
2
by: Manglio | last post by:
Well, I'm trying to delete / modify rows from a database that the program created before. But I cant get it to work. This is my code: DataSet Dset = new DataSet(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.