gpt4 book ai didi

c# - 为什么 DataRow 在方法的一部分中被识别而不是在另一部分中(我如何动态添加 DataRows)?

转载 作者:太空狗 更新时间:2023-10-29 22:05:14 24 4
gpt4 key购买 nike

使用这段代码:

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;

...我使用第 1 行(第 2a 和 2b 行被注释掉)或使用第 2a 和 2b 行(第 1 行被注释掉)得到这个编译时错误:

'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' 由于其保护级别而无法访问

这让我感到困惑,因为 for 循环中的 DataRow 是可以容忍的。如何将这些数据行添加到我的 OracleDataTable?

最佳答案

DataRow 的构造函数被标记为protected internal,因此,您不能直接构造它。

DataTable 获取新行的正确代码是

DataRow dr = dt.NewRow();

关于c# - 为什么 DataRow 在方法的一部分中被识别而不是在另一部分中(我如何动态添加 DataRows)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12081875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com