在foreach C#中将行追加到数据表 [英] Append rows to datatable in foreach c#

查看:52
本文介绍了在foreach C#中将行追加到数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi,

DataTable dt = new .DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Property", typeof(string));
                                           
foreach (Object form in Obj)

{

string str1 = "hi";

string str2 = "hey";

dt.Rows.Add(str1, str2);

}

现在,我需要一一追加行.上面的代码仅添加了当前行,如何在现有行之上添加行?
真的很感谢任何建议吗?

Now I need to append rows one by one. The above code only adds the current rows and how can I add rows on top of the existing ones?
Really appreciate any suggestions?

推荐答案

嘿Vickey,

Hey Vickey,

row = table.NewRow(); row["Name"] = "hi"; row["Property"] = "hey";

table.Rows.Add(行);

table.Rows.Add(row);

以上将会附加....

检查一次您的Foreach循环

Check you Foreach loop Once


这篇关于在foreach C#中将行追加到数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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