I would like to add a new row in an existing table. I want to create a new row with the NewRow method and put the values on the same line.
DataTable dtTable1 = new DataTable();
dtTable1.Rows.Add(new DataColumn(NCdeTCMParametrs.NombreCol1), typeof(string));
dtTable1.Rows.Add(new DataColumn(NCdeTCMParametrs.NombreCol2()), typeof(string));
dtTable1.Rows.Add(dtTable1.NewRow() { new object[] { datCol1, string.Join(",", listCol2) } });
I can't find the correct syntax for it to be accepted. What is the mistake?
You just need to use
DataRowCollection.Addthat takes anObject[]:DataTable.NewRowis used if you want to initialize each field separately, so you don't need it if you want to pass the whole array at once. You could also useNewRowand initialize all fields at once withItemArray, but you need multiple lines:A third option is to add an empty row and afterwards modify the already added row: