daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 16th, 2018 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. string path = Directory.GetCurrentDirectory();
  2.             string csvPath = Path.GetFullPath(Path.Combine(path, @"..\..\Files\Demo.csv"));
  3.             DataTable dt = new DataTable();
  4.             dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Id", typeof(int)),
  5.             new DataColumn("Name", typeof(string)),
  6.             new DataColumn("Technology", typeof(string)),
  7.             new DataColumn("Company", typeof(string)),
  8.             new DataColumn("Country",typeof(string)) });
  9.             string csvData = File.ReadAllText(csvPath);
  10.             foreach (string row in csvData.Split('\n'))
  11.             {
  12.                 if (!string.IsNullOrEmpty(row))
  13.                 {
  14.                     dt.Rows.Add();
  15.                     int i = 0;
  16.                     foreach (string cell in row.Split(','))
  17.                     {
  18.                         dt.Rows[dt.Rows.Count - 1][i] = cell;
  19.                         i++;
  20.                     }
  21.                 }
  22.             }
  23.             dgvCSV.DataSource = dt;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top