Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 7-Jan-13 19:22pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

 // 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
 
for (int i = 0; i < table.Rows.Count; i++)
           {
               for (int j=0;j<table.Columns.Count;j++)
               {
                   Console.WriteLine(table.Rows[i][j]);
               }
           }
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 8 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100