Below is my class code
public class TextReaderClass
{
public DataTable ReadTextFile(string filepath)
{
DataTable dtTextFile = new DataTable();
dtTextFile.Columns.Add("Emp_Id");
dtTextFile.Columns.Add("Emp_FirstName");
dtTextFile.Columns.Add("Emp_LastName");
dtTextFile.Columns.Add("Emp_Designation");
dtTextFile.Columns.Add("Emp_Salary");
dtTextFile.Columns.Add("Emp_JoiningDate");
//CODE to add here reading from text file and filling the data table
string[] readTextfile = System.IO.File.ReadAllLines(@"D:\Rutu\datatest.txt");
//Run a loop here for each record in the text file
foreach (string line in readTextfile)
{
var cols = line.Split(';');
DataRow dtrow = dtTextFile.NewRow();
//Create an object of Data Row
dtTextFile.Rows.Add(dtrow);
//Fill the row data in DataTable
}
return dtTextFile;
}
}
I tried this CODE for reading from text file and filling the data table. Any help will be highly appreciated. Thanks