DataTable没有获得更新? [英] DataTable do not get updates?

查看:87
本文介绍了DataTable没有获得更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataTable,其中一列填充了文本文件中的单词列表,我创建了一个方法来读取字符串,如果创建了该字符串,则必须删除该行,但问题是DataTable没有得到更新。



  foreach 字符串文件中)
{
tagst.Rows.Add(line)
}

string s;
for int k = 0 ; k < tagst.Rows.Count; k ++)
{
s = tagst.Rows [k] [ 标签]。ToString();
if (s.Equals( Jad ))
{
tagst.Rows [k] .Delete();
}
}

解决方案

删除不会从DataTable中删除该行。它标记要删除的行。



如果您在DataTable上调用AcceptChanges或您更改了DataRow,那么该行将从DataTable中删除。

I have a DataTable with one column filled with list of words from a text file, I create a method to read a string if the string is founded the row must be deleted, but the problem is that the DataTable don't get the updates.

foreach(string line in file)
{
   tagst.Rows.Add(line)
}

string s;
for (int k = 0; k < tagst.Rows.Count; k++)
{
   s = tagst.Rows[k]["Tags"].ToString();
   if(s.Equals("Jad"))
   {
      tagst.Rows[k].Delete();
   }
}

解决方案

Delete does not remove the row from the DataTable. It tags the row to be deleted.

If you call AcceptChanges on the DataTable or the DataRow you changed, THEN the row will be removed from the DataTable.


这篇关于DataTable没有获得更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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