将行添加到DataTable [英] Add Row to a DataTable

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

问题描述

我创建了与DatatBase隔离/断开连接的临时DataTable,然后使用下面的代码将新行添加到表中。但是,通过对数据表的调试视图,新行中不存储任何值。如何解决这个问题?谢谢。

I created tempory DataTable that is isolated/disconnected to DatatBase, and then add a new Row to the table using the piece of code below. However, through debugging view on the datatable, no values is stored in the new row. How can this problem be fixed? Thanks.

DataTable dt = (DataTable)Session["dt_HPosition_Temp"];
DataRow dRow = SetHPosition(dt.NewRow());  // this set the row w/ values
dt.Rows.Add();
dt.AcceptChanges();

推荐答案





哎呀,你忘了将新行添加到数据表中!



更改:

Hi,

Oops, you forgot to add the new row to your datatable!

Change:
dt.Rows.Add();





To:



To:

dt.Rows.Add(dRow);





...希望它有所帮助。



... hope it helps.


这篇关于将行添加到DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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