Wednesday, 28 March 2018

code

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int counter = 1;
            string line;
            DataTable dt = new DataTable();
            DataColumn column1 = new DataColumn("Id", System.Type.GetType("System.Int32"));
            DataColumn column2 = new DataColumn("Record", System.Type.GetType("System.String"));

            dt.Columns.Add(column1);
            dt.Columns.Add(column2);

            // Read the file and display it line by line. 
            System.IO.StreamReader file =
                new System.IO.StreamReader(@"E:/Study/Concepts/ConsoleApplication1/ConsoleApplication1/readfile.txt");
            while ((line = file.ReadLine()) != null)
            {
                System.Console.WriteLine(line);
                DataRow dr = dt.NewRow();
                dr[0] = counter;
                dr[1] = line.ToString();
                dt.Rows.Add(dr);
                counter++;
            }

            file.Close();
            System.Console.WriteLine("There were {0} lines.", counter);
            // Suspend the screen. 
            System.Console.ReadLine();
        }
    }
}

No comments:

Post a Comment