I have a DataTable which contains 3 columns
id name val
1 a 2
2 b 3
3 c 4
4 d 12
5 e 14
there are five variables string a,string b,string c,string d,string e.I want to assign a value,from name column a value which is 2 to variable a,similary b value to variable b.I have done it this way
a = dt.Rows[0]["val"]
b = dt.Rows[1]["val"]
c = dt.Rows[2]["val"]
d = dt.Rows[3]["val"]
e = dt.Rows[4]["val"]
this is assigning values,but the way is going wrong.Please do let me know the other way i am stuck on this.
Regards,
Aniket Narvankar


Rajesh Sahoo102 reputationPosted Jun 14, 2016, 10:57 PM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 14, 2016, 10:57 PM EDT
Aniket NarvankarRank #903 · 2.3K reputationPosted Jun 14, 2016, 11:07 PM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jun 14, 2016, 11:30 PM EDT
Since you want to get thevalues from the each row and assign to the separate "string"variables, this is thepossibleway AFAIK. I think, you feel that the code is repeated multiple times. But this is how you need to achieve this one.
Rajesh Sahoo102 reputationPosted Jun 14, 2016, 11:36 PM EDT
Vinay SinghRank #604 · 4K reputationPosted Jun 15, 2016, 12:15 AM EDT
Aniket NarvankarRank #903 · 2.3K reputationPosted Jun 15, 2016, 8:22 PM EDT
Francis SusaimichaelRank #466 · 5.4K reputationPosted Jun 15, 2016, 9:23 PM EDT
@Aniket,If you need anyother solution like yours then we can include using if..else statement instead of switch..case inside for loop. Wecan try with while..loop too.In my perspectiveI don't think, howthese options are considered as alternatives.
Since your ultimate result needs get thevalues from the each row and assign to the separate "string"variables. :)