Telerik gridview:如何在更改数据库后刷新网格视图 [英] Telerik gridview : How to refresh grid view after Database change

查看:212
本文介绍了Telerik gridview:如何在更改数据库后刷新网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#winform应用程序中使用 radgridview 来显示数据库中的数据。我也在通过ADO.Net更改数据库。问题是更改数据库(例如,通过删除行或添加新行)后,更改不会出现在gridview中。
我还想提到我已通过智能标记将数据库绑定到gridview当我尝试创建一个新的数据集并将其分配给 radgridview1.datasource 时,我遇到了很多错误。

关于如何强制 radgridview 重新加载它的数据源吗?

I'm using radgridview in C# winform application to show data from database. I'm also altering database through ADO.Net. The problem is after I change the database, for example by deleting a row or adding a new row, changes do not appear in gridview.
I also want to mention that I have bound database to gridview through smart tags and when I tried to create a new dataset and assign it to radgridview1.datasource I got tons of errors.
Any suggestion on how can force radgridview to reload it's datasource ?

推荐答案

好吧,我自己找到了答案。尽管它仅适用于 dataGridView ,而不适用于 dataListView

删除记录并提交对数据库的更改:

Well, I found the answer myself. Although it only works on dataGridView and doesn't work on dataListView.
To delete a record and commit changes to database :

radGridView1.CurrentRow.Delete();
this.yourTableAdapter.Update(yourDataSet);

另一方面,如果您添加了新记录并希望重新整理列表:

On the other hand, if you have added new records and you want to reform the list :

this.yourTableAdapter.Fill(yourDataSet.yourTabel);

如果您知道如何使用 dataListView ,我会很高兴听到。

If you know how to do the same with dataListView, I'll be glad to hear.

这篇关于Telerik gridview:如何在更改数据库后刷新网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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