Advertisement
Ortund

Untitled

Sep 2nd, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1.         private void ReadData(TextReader Source)
  2.         {
  3.             string txt = Source.ReadToEnd();
  4.             List<String> lst = new List<String>();
  5.  
  6.             string[] items = txt.Split(Convert.ToChar(Environment.NewLine));
  7.  
  8.             DataTable dt = new DataTable();
  9.  
  10.             foreach (string s in items) // actual rows
  11.             {
  12.                 string[] cols = null;
  13.  
  14.                 if (s.Contains(",")) // check if the row has multiple columns
  15.                 {
  16.                     cols = s.Split(',');
  17.  
  18.                     DataRow r = dt.NewRow();
  19.                     foreach (string col in cols) // actual columns
  20.                     {
  21.                         dt.Columns.Add();                        
  22.                     }
  23.  
  24.                     int i = 0;
  25.                     foreach (string col in cols) // actual columns
  26.                     {
  27.                         r[i] = col;
  28.                         i++;
  29.                     }
  30.                 }
  31.             }
  32.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement