c# - 在数据表c#中的下一个位置复制并插入现有行
问题描述
我有一个数据表,需要在原始数据下方复制一行 x 次(由 xMulti 命名)。我怎么能做到这一点?我的例子给出了一个错误。
int xMultiPos = 0;
if (DtTbl.Columns.Contains("xMulti"))
{
xMultiPos = DtTbl.Columns.IndexOf("xMulti"); // set the position of the multiplikator
foreach (DataRow row in DtTbl.Rows)
{
int xMultiplicatorTemp = int.Parse((string)row[xMultiPos]); // convert the multiplicator to an int value
if (xMultiplicatorTemp > 1)
{
TB_Info.Text = "vorhanden";
for (int i = 0; i < xMultiplicatorTemp; i++)
{
int index = DtTbl.Rows.IndexOf(row);
try
{
DataRow temp = (DataRow)row[index]; // this will not work, because it is text?
DtTbl.Rows.InsertAt(temp, index);
}
catch (Exception msg)
{
Debug.WriteLine(msg);
throw;
}
}
}
}
}
解决方案
推荐阅读
- java - 带有不同按钮的黄瓜场景大纲
- java - 测试返回 StreamingResponseBody 的下载操作
- c# - 不能在此范围内声明名为“student”的本地或参数,因为该名称在封闭的本地范围中用于定义本地参数
- php - 如何在关联数组中指定变量,在循环中获取值并插入数据库
- java - 如何在 Java 程序的开头加载一个表?
- typescript - 将类型断言与解构赋值一起使用的最佳方法是什么?
- powershell - 比较来自 2 个 OU 的用户,只有当他们不同时才输出
- python - 根据条件重复列的值
- java - java计时器中疾病传播的公式
- authentication - 用于身份验证目的的大使 Api 网关 k8s 中的 b/w 微服务