Update a DataRow in a DataTable;
-
Hi I just wanted to know the proper way of updating a DataRow. If I have a DataTable say locDTable which already has rows populated through
Iterate { DataRow locDRow = locDTable.NewRow(); //Put DataRow values here locDTable.Rows.Add(locDRow); }
How do I access (and modify a particular column entry for a particular row? The way I would do it something like:locDTable.Rows[rowIndex][colIndex] = newValue;
Is this the proper way? Thank you in advance! j11Software -
Hi I just wanted to know the proper way of updating a DataRow. If I have a DataTable say locDTable which already has rows populated through
Iterate { DataRow locDRow = locDTable.NewRow(); //Put DataRow values here locDTable.Rows.Add(locDRow); }
How do I access (and modify a particular column entry for a particular row? The way I would do it something like:locDTable.Rows[rowIndex][colIndex] = newValue;
Is this the proper way? Thank you in advance! j11SoftwareHi Maybe, instead of access to the column by an index you can use strings constants to access to columns. It seems more elegant and if you change the structure of the table the acces to the previous column doesn't change. To access to a particular row the only way is by an index.
-
Hi Maybe, instead of access to the column by an index you can use strings constants to access to columns. It seems more elegant and if you change the structure of the table the acces to the previous column doesn't change. To access to a particular row the only way is by an index.
I agree 100% with the constants approach for column names, we do that all the time here and has paid of on numerous occasions. We also do it for the table names. It decouples you from Database especially for column name changes (just change constant literal) as well as makes the code much more readable.
Christopher Pond Innovative Technology Solutions SpartanSoft.net.