Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CompareLinuxWithWindow
- {
- class Program
- {
- static void Main(string[] args)
- {
- ConvertToDataTable(@"C:UsersmanchunlDesktopSample.txt", 10);
- Console.WriteLine();
- Console.WriteLine("Press enter to exit.");
- Console.Read();
- }
- public static DataTable ConvertToDataTable(string filePath, int numberOfColumns)
- {
- DataTable tbl = new DataTable();
- for (int col = 0; col < numberOfColumns; col++)
- tbl.Columns.Add(new DataColumn("Column" + (col + 1).ToString()));
- string[] lines = System.IO.File.ReadAllLines(filePath);
- foreach (string line in lines)
- {
- var cols = line.Split(',');
- DataRow dr = tbl.NewRow();
- for (int cIndex = 0; cIndex < 10; cIndex++)
- {
- dr[cIndex] = cols[cIndex];
- }
- tbl.Rows.Add(dr);
- }
- return tbl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement