Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want read some of data from datatable with for loop condition .in that datatable I want read some particular rows and column data with help of some row no (10 to 15) and (column no 5 to 10)

DataTable tbl = new DataTable();

for(tbl.row=10; tbl.row<=15;tbl.row++)
         {
                 for(tbl.colum=5; tbl.colum<=10;lt;=15;tbl.colum++)
                       {
                          string cell=[tbl.row].[tbl.colum]
                         }
           }
Posted

1 solution

C#
//dataTab is the datatable

//reading all the data for all rows and columns.
for (int j = 0; j < dataTab.Rows.Count; j++)
{
    for (int i = 0; i < dataTab.Columns.Count; i++)
    {
        Console.WriteLine(dataTab.Rows[j][i]);
    }
}

//Reading data for rows 10 to 15 and columns 5 to 10
//j is used for rows
for (int j = 9; j < 15; j++)
{
    //i is used for columns
    for (int i = 4; i < 10; i++)
    {
        Console.WriteLine(dataTab.Rows[j][i]);
    }
}
 
Share this answer
 
v4
Comments
Maciej Los 17-Mar-15 2:57am    
j=10 it means start from row no. 11 ;)
Subramanyam Shankar 17-Mar-15 4:53am    
Thanks :)
Member 10562086 17-Mar-15 6:27am    
thanks for your reply :)
Subramanyam Shankar 17-Mar-15 6:32am    
You are welcome :)
Member 10562086 17-Mar-15 6:40am    
Sir . I have one excel sheet,the excel sheet data and what ever data from datatable data both are same . i want compare both "datatable" data and excel sheet each cell data .please help on that ,if both data is same then i want display message ,,other wise i have to display message ,,like "data miss match in excel sheet and Datatable data in row no 8 and column 10" like that ,please help me

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