Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heyy...
I have dataset of values ...I want to put this in a forloop..can you help me..


ds.Tables[0].Rows[1][2] = "40";
ds.Tables[0].Rows[2][3] = "40";
ds.Tables[0].Rows[3][4] = "40";
ds.Tables[0].Rows[2][2] = "41";
ds.Tables[0].Rows[3][3] = "41";
ds.Tables[0].Rows[3][2] = "42";
Posted

1 solution

C#
// Get the data table.
   foreach (DataRow row in ds.Tables[0].Rows) // Loop over the rows.
   {

       foreach (var item in row.ItemArray) // Loop over the items.
       {
                  //do actions or assign values
                   item="something"
       }
   }


or alternative with for

C#
for (int i = 0; i < table.Rows.Count; i++)
           {
               for (int j=0;j<table.Columns.Count;j++)
               {
                   Console.WriteLine(table.Rows[i][j]);
               }
           }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900