如何动态地将列和行添加到空数据集中?
我创建了一个新的数据集,因为
DataSet local_ds2 = new DataSet();
我尝试动态添加行和列
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() + "'";
}
,但我无法动态添加列和行,任何人都可以帮助我
I created a new dataset as
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将代码更改为此
您没有将行添加到数据表中
Try changing your code to this
You are not adding the rows to the Datatable
应该像...
should be like...
尝试将数据列放入表行中,然后将表行添加到表中。现在看起来您正在向表中添加一列,跳过行的步骤
try putting the datacolums in a tablerow and then adding the tablerow to the table. Right now it looks like you're adding a column to a table skipping the step of the rows