How can I dynamically add colums and rows to an empty dataset?(如何将列和行动态添加到空数据集中?)
本文介绍了如何将列和行动态添加到空数据集中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个新数据集
DataSet local_ds2 = new DataSet();
我试过这个动态添加行和列
I tried this to add rows and columns dynamically
DataColumn dcAmount = new DataColumn("EmpID");
local_ds2.Tables["ACHFile"].Columns.Add(dcAmount);
DataColumn dcName = new DataColumn("Name");
local_ds2.Tables["ACHFile"].Columns.Add(dcName);
DataColumn dcBnkRoutingNumber = new DataColumn("BankRoutingNumber");
local_ds2.Tables["ACHFile"].Columns.Add(dcBnkRoutingNumber);
DataColumn dcBnkAccount = new DataColumn("BankAccount");
local_ds2.Tables["ACHFile"].Columns.Add(dcBnkAccount);
DataColumn dc = new DataColumn("Amount");
local_ds2.Tables["ACHFile"].Columns.Add(dc);
DataColumn dc1 = new DataColumn("BankAccountTypeID");
local_ds2.Tables["ACHFile"].Columns.Add(dc1);
for (int i = 0; i < chkcnt; i++)
{
local_ds2.Tables["ACHFile"].Rows[i]["EmpID"] = EmpID[i];
local_ds2.Tables["ACHFile"].Rows[i]["Name"] = Empname[i];
local_ds2.Tables["ACHFile"].Rows[i]["BankRoutingNumber"] = BnkRoutingNumber[i];
local_ds2.Tables["ACHFile"].Rows[i]["BankAccount"] = BnkAccount[i];
local_ds2.Tables["ACHFile"].Rows[i]["BankAccountTypeID"] = AchDB.strBankTypeID[i];
local_ds2.Tables["ACHFile"].Rows[i]["Amount"] = AchDB.Amount1[i];
if (AchDB.strBankTypeID[i].ToString() == "D")
strBankAccntType = "BankAccountTypeID='" + AchDB.strBankTypeID[i].ToString() + "'";
}
但我无法动态添加列和行,任何人都可以帮助我
But I am unable to add columns and rows dynamically can any one help me
推荐答案
试着把你的代码改成这个
Try changing your code to this
DataRow dr;
for (int i = 0; i < chkcnt; i++)
{
dr = local_ds2.Tables["ACHFile"].NewRow();
dr["EmpID"] = EmpID[i];
dr["Name"] = Empname[i];
dr["BankRoutingNumber"] = BnkRoutingNumber[i];
dr["BankAccount"] = BnkAccount[i];
dr["BankAccountTypeID"] = AchDB.strBankTypeID[i];
dr["Amount"] = AchDB.Amount1[i];
if (AchDB.strBankTypeID[i].ToString() == "D")
strBankAccntType = "BankAccountTypeID='" + AchDB.strBankTypeID[i].ToString() + "'";
local_ds2.Tables["ACHFile"].Rows.Add(dr);
}
您没有将行添加到数据表中
You are not adding the rows to the Datatable
这篇关于如何将列和行动态添加到空数据集中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何将列和行动态添加到空数据集中?
基础教程推荐
猜你喜欢
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01