Advertisement
Guest User

Untitled

a guest
May 16th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement