Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can we make the below Datatable subtraction method as generic
  2. private DataTable DtSubtract(DataTable dt, int insertAt)
  3. {
  4.     DataRow dr;
  5.     List<object> lstColumnSummation = new List<object>();
  6.     double res = 0;
  7.  
  8.     for (int i = 0; i < dt.Columns.Count; i++)
  9.     {
  10.     for (int row = 0; row < dt.Rows.Count; row++)
  11.         res = Convert.ToDouble(dt.Rows[row][i]) - res;
  12.  
  13.     lstColumnSummation.Add(-(res));
  14.     res = 0;
  15.     }
  16.     //add a new data row
  17.     dr = dt.NewRow();
  18.     dr.ItemArray = lstColumnSummation.ToArray();
  19.     //insert the row at the position specified
  20.     dt.Rows.InsertAt(dr, insertAt);
  21.     //accept the changes
  22.     dt.AcceptChanges();
  23.     return dt;
  24. }
  25.        
  26. First is: double res = 0; TO int res = 0;
  27.  
  28. Second is:   res = Convert.ToDouble(dt.Rows[row][i]) - res; TO res = Convert.ToInt32(dt.Rows[row][i]) - res;