I tried like this:
public Datatable GetDatatable(){
string[] csv=@"1,ABC,Arun,12/12/2017\n
2,BCD,Sam,10/12/2017\n
3,XYZ,Ammy,11/12/2017\n
4,PQR,Varun,9/12/2017\n";
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
foreach (var line in csv)
{
string[] l=line.split(',');
table.Rows.Add(l[0]);
table.Rows.Add(l[1]);
table.Rows.Add(l[2]);
table.Rows.Add(l[3]);
}
return table;
}
csv like
1,ABC,Arun,12/12/2017
2,BCD,Sam,10/12/2017
3,XYZ,Ammy,11/12/2017
4,PQR,Varun,9/12/2017
It is done by using foreach. I want same result without using for loop or foreach because CSV contain above 3 million lines. Please give some ideas or suggestions.