如何将新列添加到数据表? [英] How to add new column to a datatable?

查看:89
本文介绍了如何将新列添加到数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下但我没有得到匹配的值,单元格是空的。



I tried the below but I don't get the values of Matching, the cells are empty.

t1= t2.Clone();
match2 = t1.NewRow();
t1.Columns.Add("Matching");

foreach(DataRow r in t1.Rows)
{
n = tags.Select("Title= '" + r["Title"] + "'");
    foreach (DataRow roo in n)
    {
         t1.ImportRow(roo);
         match2["Matching"] = getscore();
    }
}

推荐答案

添加新行后,您应该为其所有列添加值,特别是对于它的PKs字段。
After you add a new row you should add value for each of all its columns, and especially for its PKs fields.


你应该使用Copy()而不是Clone()。克隆只复制结构,但复制方法复制结构和数据。



所以使用



t1 = t2.Copy();



而不是



t1 = t2 .Clone();
You should be using Copy() instead of Clone(). Clone only copies the structure but copy method copies both structure and data.

So use

t1 = t2.Copy();

instead of

t1= t2.Clone();


<>>>>>>





t1 = t2.copy()
<>>>>>>


t1=t2.copy()


这篇关于如何将新列添加到数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆