With this code:
OracleDataTable dt = PlatypusSchedData.GetAvailablePlatypi();
OracleDataTable outputDt = new OracleDataTable();
int iRows = 12;
while (iRows > 0)
{
outputDt.Rows.Add(new DataRow()); // line 1
//var dr = new DataRow(); // line 2a
//outputDt.Rows.Add(dr); // line 2b
iRows -= 1;
}
for (int i = 0; i < dt.Rows.Count; i += 1) {
DataRow dr = dt.Rows[i];
int outputColumn = 0;
if (i % 12 == 0 && i > 0) {
outputColumn += 1; //2?
}
outputDt.Rows[i % 12][outputColumn] = dr[0];
outputDt.Rows[i % 12][outputColumn + 1] = dr[1];
}
dataGridView1.DataSource = outputDt;
...I get this compile-time error using either line 1 (lines 2a and 2b commented out) or using lines 2a and 2b (with line 1 commented out):
'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level
This is baffling me because the DataRow in the for loop is tolerated. How can I add these DataRows to my OracleDataTable?
A data row is an individual data source record. Rows contain data and command cells. Data cells display field values.
To create a new DataRow, use the NewRow method of the DataTable object. After creating a new DataRow, use the Add method to add the new DataRow to the DataRowCollection. Finally, call the AcceptChanges method of the DataTable object to confirm the addition.
A DataRow is created by calling the NewRow( ) method of a DataTable , a method that takes no arguments. The DataTable supplies the schema, and the new DataRow is created with default or empty values for the fields: // create a table with one column DataTable dt = new DataTable(); dt. Columns.
The constructor for DataRow
is marked as protected internal
, and as such, you cannot construct it directly.
The correct code to get a new row for a DataTable
is
DataRow dr = dt.NewRow();
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