Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading values from DataTable

Tags:

c#

datatable

I have a DataTable populated with samo data/values and I want to read data from DataTable and pass it to a string variable.

I have this code:

DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];

I have a countert like this:

for (int i = 1; i <= broj_ds; i++ )
{                                    
    QuantityInIssueUnit_value => VALUE FROM DataTable
    QuantityInIssueUnit_uom  => VALUE FROM DataTable    
}

Is this possible or not? If yes then how to pass data from DataTable to those variables?

Thanks!

like image 262
CrBruno Avatar asked Jul 19 '12 08:07

CrBruno


Video Answer


2 Answers

DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];

for (int i = 0; i < dr_art_line_2.Rows.Count; i++)
{
    QuantityInIssueUnit_value = Convert.ToInt32(dr_art_line_2.Rows[i]["columnname"]);
    //Similarly for QuantityInIssueUnit_uom.
}
like image 72
Nikhil Agrawal Avatar answered Nov 11 '22 01:11

Nikhil Agrawal


You can do it using the foreach loop

DataTable dr_art_line_2 = ds.Tables["QuantityInIssueUnit"];

  foreach(DataRow row in dr_art_line_2.Rows)
  {
     QuantityInIssueUnit_value = Convert.ToInt32(row["columnname"]);
  }
like image 24
HatSoft Avatar answered Nov 11 '22 02:11

HatSoft