Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string path = Directory.GetCurrentDirectory();
- string csvPath = Path.GetFullPath(Path.Combine(path, @"..\..\Files\Demo.csv"));
- DataTable dt = new DataTable();
- dt.Columns.AddRange(new DataColumn[5] { new DataColumn("Id", typeof(int)),
- new DataColumn("Name", typeof(string)),
- new DataColumn("Technology", typeof(string)),
- new DataColumn("Company", typeof(string)),
- new DataColumn("Country",typeof(string)) });
- string csvData = File.ReadAllText(csvPath);
- foreach (string row in csvData.Split('\n'))
- {
- if (!string.IsNullOrEmpty(row))
- {
- dt.Rows.Add();
- int i = 0;
- foreach (string cell in row.Split(','))
- {
- dt.Rows[dt.Rows.Count - 1][i] = cell;
- i++;
- }
- }
- }
- dgvCSV.DataSource = dt;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement