How To Read Data From CSV File using X++
public static void main(Args _args)
{
#File
IO iO;
str SO_ID;
str Name;
Table1 _table1;
FilenameOpen filename = @"C:\Users\Adminfdc3207d2d\Desktop\info.csv";
//To assign file name
Container record;
boolean first = true;
;
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
SO_ID = conpeek(record, 1);// fetch records from first column
Name = conpeek(record, 2); // fetch records from second column
_table1.Nme = SO_ID; // Table1 stores records of first column in Nme field.
_table1.insert();
info("File inserted in the Table");
}
}
}
}
Comments
Post a Comment