How to set a same value to all rows in a particular column in datatable

Posted by T.saravanan under C# on 8/4/2010 | Views : 19652 | Status : [Member] [MVP] | Replies : 3
Hi,
I have a data table with data.Now i have change all rows value in a particular column to avoid looping concept.
For example .My data table first column name is Percentage and No.of rows is 100.The row values are different.But now i set all rows value in 50.
How to set the value into all the rows.Now i done using for loop concept.But my question is any method is there to avoid the for loop to change the rows value in a particular column.

Advance Thanks,
T.Saravanan

Thanks,
T.Saravanan



Responses

Posted by: Poster on: 8/4/2010 [Member] Starter

Up
0
Down
Thats a very good question, however difficult to answer. I think the way you are doing is fine.


T.saravanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 8/6/2010 [Member] Bronze

Up
0
Down
You can achieve this by DefaultValue property of datatable.

You can create the datatable

DataTable objDataTable = new DataTable();


Now add the Column
DataColumn objDataColumn = new DataColumn();

objDataColumn.DefaultValue = "50";


objDataColumn.Columns.Add(objDataColumn);


So, this way you can achieve the solution for the problem without loop...

Thanks,

T.saravanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetnoob on: 6/13/2011 [Member] Starter | Points: 25

Up
0
Down
Nice code Neeks. Thanks for sharing this!

T.saravanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response