简体   繁体   English

dataTable在运行时添加列

[英]dataTable add column in run time

Hello Every one I m stuck in one problem but I don't how to resolve it 你好,我每个人都陷入一个问题,但我不知道如何解决

I have dataTable InvoiceViewWithUserDataTable related to view : InvoiceWithUserView (database) 我有与视图相关的dataTable InvoiceViewWithUserDataTable:InvoiceWithUserView(数据库)

I want to add 2 columns in run time to datatable InvoiceViewWithUserDataTable 我想在运行时向数据表InvoiceViewWithUserDataTable添加2列

InvoiceViewWithUserDataTable .Columns.Add("IntegrationSuccessed", GetType(Integer))
 InvoiceViewWithUserDataTable .Columns.Add("ResponseGet", GetType(String))

InvoiceViewWithUserDataTable.FillMyData(startindex, lineNumber)

Foreach(var row  in InvoiceViewWithUserDataTable)
{
    row.ResponseGet (error)
    row.IntegrationSuccessed (error)

}

but the in results I can't get the value for this 2 column even if my stored pro return them 但是即使我存储的专家返回了它们,结果我也无法获得这2列的值

Try this--- 尝试这个 - -

InvoiceViewWithUserDataTable.Columns.Add("NewColumn", typeof(System.Int32)); InvoiceViewWithUserDataTable.Columns.Add(“ NewColumn”,typeof(System.Int32));

foreach(DataRow row in InvoiceViewWithUserDataTable .Rows) foreach(InvoiceViewWithUserDataTable中的DataRow行。行)
{ {
//need to set value to NewColumn column //需要将值设置为NewColumn列
row["NewColumn"] = 0; row [“ NewColumn”] = 0; // or set it to some other value //或将其设置为其他值
} }

Also, you are populating the data from the database then it clear the existing data or create a new data table object. 同样,您正在从数据库填充数据,然后清除现有数据或创建新的数据表对象。 First, get the data from the database then add a new column and after that insert values in these columns. 首先,从数据库中获取数据,然后添加一个新列,然后在这些列中插入值。
Also, refer the following link for run time column 另外,请参阅以下链接以获取运行时列
Add new column and data to datatable that already contains data - c# 将新列和数据添加到已包含数据的数据表-C#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM