0
votes

I have a DataTable called dataTable that has two columns Col1 and Col2 and it contains five rows all initialized to null. How would I set the values in Col1 and Col2 to "1" and "2" respectively without using a for loop or foreach loop for each DataRow?

1
why do you need it? and what have you done so far? - vivek nuna
dt.Columns["Col1"].DefaultValue = "1"; dt.Columns["Col2"].DefaultValue = "2"; - vivek nuna
@viveknuna this will affect the rows added after you set the DefaultValue. If the rows are already in the datatable they will not be changed by this settings - Steve
dt.Columns["col1"].Expression = "'1'"; dt.Columns["col2"].Expression = "'2'"; - vivek nuna
There is no "the best" way to implement features but OP's demand is definitely not good at any extent. - Nathan

1 Answers

0
votes

Use 10 assignment statements. No loop required.