how to loop through datarow in c#
  • hello

    Please tell me how can i loop through datareader or data rows in c#. i am using following code to loop through rows.

      using (var r = cm.ExecuteReader())
    int[] yValue = new int[1];
    int pointer = 0;
    foreach (DbDataRecord s in r)
    string item = "*0000"+s["item_id"].ToString()+"*";
    int xValue = 10;
    e.Graphics.DrawString(item, new Font("Free 3 of 9", 30, FontStyle.Regular), Brushes.Black, xValue, yValue[pointer]);

    string y = yValue[pointer].ToString();
    pointer ++;


    I want to increment value of yValue on each row/iteration. but in above code value of yValue is not changing. Please tell me how can i do this.
  • 2 Comments sorted by
  • you can get your data in datatable and for loop on datatable you can use below code.

    foreach(DataRow dr in dt.Rows)
    string ColumnValue=dr["ColumnName"].ToString();

  • @Waqas
    its ok but i have to increment the value of yValue as well. which is not happening. i want to add 30 to the value of yValue as well. Please check my code.


Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook


Popular Posts of the Week

    Optimum Creative