Is it possible to add a few rows to a DataTable with a single call?
The issue is that I need to create a DataTable where each column requires a previous processing before being written into the DataTable. Writing row by row would be inconvenient.
I.e., I need to create a DataTable with N empty rows and later write values in a column basis.
create temporary table (TMP) with the only columns consisting PrimaryKey matching DST. PriaryKey (without any rows yett) merge data from DST to TMP - this will create just rows. manually add columns matching SRC - this will create "empty" rows.
To add or insert observation/row to an existing Data Frame in R, we use rbind() function. We can add single or multiple observations/rows to a Data Frame in R using rbind() function. The basic syntax of rbind() is as shown below.
You cannot add multiple rows without loops. If you want to add n
rows to a DataTable
where all columns are "empty" use DataRowCollection.Add
without arguments:
for(int i = 0; i < n; i++)
table.Rows.Add(); // all fields get their default value
in your for loop, (obviously needs a forloop to add multiple rows), you want to use
for(int i = 0; i < n; i++)
table.Rows.Add();
if you know what you want to put in the row, you can tweak this code:
DataRow newBlankRow = theDataTable.NewRow();
theDataTable.Rows.InsertAt(newBlankRow, theDataTable.Rows.Count);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With