从数据表中删除数据行
假设我有一个数据表 dt(它包含广告商),并且我想从 dt 中删除一行,其中advertiserID 等于一个值,我该怎么做?
DataTable dt = new DataTable();
//populate the table
dt = DynamicCache.GetAdvertisers();
//I can select a datarow like this:
DataRow[] advRow = dt.Select("advertiserID = " + AdvID);
//how do you remove it, this get's me an error
dt.Rows.Remove(advRow)
那么如何正确地做到这一点呢?
谢谢。
Lets say I have a datatable dt (it contains advertisers) and I want to remove a row from dt where the advertiserID equals a value, how do I do that?
DataTable dt = new DataTable();
//populate the table
dt = DynamicCache.GetAdvertisers();
//I can select a datarow like this:
DataRow[] advRow = dt.Select("advertiserID = " + AdvID);
//how do you remove it, this get's me an error
dt.Rows.Remove(advRow)
so how do you do it correctly?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
advRow 是一个数组。您必须确定要删除数组中的哪一行。
当然,这只是将其从数据表中删除,不一定是其背后的数据源(sql,xml,...)。这将需要更多...
并且在选择后检查数组或迭代数组将是一个好主意...
advRow is an ARRAY. You have to identify which row in the array to delete.
of course, this only removes it from the datatable, not necessarily the data source behind it (sql, xml, ...). That will require more...
and it would be a good idea to check the array or iterate the array after the select...