刷新datagridview错误 [英] Refresh datagridview error

查看:67
本文介绍了刷新datagridview错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有问题
我有按钮TsmRefresh,它必须是来自sql server数据库中销售表的更新数据

Hello i have problem
I have button TsmRefresh it must be update data from selling table which is in sql server database

private void TsmRefresh_Click(object sender, EventArgs e)
       {
           sqlDataAdapter1.Fill(dataSet11);
       }


当我在datagridview中按下此按钮时,添加已经在datagridview中的相同数据.一切都是双重的.按下此按钮,效果相同.
我正在使用c#,有人可以对我说什么问题?


when i press this button in datagridview adding same data which is already in datagridview. everything is double. its make same evry press in this button.
Im using c# what is problem can anybody say to me?

推荐答案

我看不到您的代码有什么问题,因此我检查了文档(
I could not see anything wrong with your code, so I examined the documentation (here[^]).

Here is a quote from that page.

如果存在主键信息,则将协调所有重复的行,并且仅在与DataSet相对应的DataTable中出现一次.可以通过FillSchema,指定DataTable的PrimaryKey属性或将MissingSchemaAction属性设置为AddWithKey来设置主键信息.
如果SelectCommand返回OUTER JOIN的结果,则DataAdapter不会为所得的DataTable设置PrimaryKey值.您必须显式定义主键,以确保正确解析重复的行.有关更多信息,请参见定义主键(ADO.NET).

If primary key information is present, any duplicate rows are reconciled and only appear once in the DataTable that corresponds to the DataSet. Primary key information may be set either through FillSchema, by specifying the PrimaryKey property of the DataTable, or by setting the MissingSchemaAction property to AddWithKey.
If the SelectCommand returns the results of an OUTER JOIN, the DataAdapter does not set a PrimaryKey value for the resulting DataTable. You must explicitly define the primary key to ensure that duplicate rows are resolved correctly. For more information, see Defining Primary Keys (ADO.NET).



所以可能是任何一个原因. 1.您的数据库中是否有正确的主键?
2.您在使用外部联接吗?



So could either of those be the cause.
1. Do you have the correct Primary Keys in your database?
2. Are you using an Outer-Join?


确定.

我只能想到要尝试的另外两件事.

1.如果使用BindingSource将数据绑定到网格,则可以尝试

OK.

I can only think of two other things to try.

1. If you are using a BindingSource to bind the data to the grid, you could try

gridBindingSource.ResetBindings();



如果您不使用BindingSource组件,那么我会认真考虑它,因为它会自动显示更新的数据.

2.使用CurrencyManager强制刷新绑定控件.



If you are not using the BindingSource Component, I would seriously consider it as it should automatically show updated data.

2. Use the CurrencyManager to force a refresh of the bound controls.

CurrencyManager cm = (CurrencyManager)this.BindingContext[dataSet11.yourDataTable]; // or possibly just (CurrencyManager)this.BindingContext[dataSet11]
cm.Refresh();


您在此处发布的代码完全没有意义.
可能是应该通过将DataSource属性设置为null来清理datagrid之前的其他事情.
很难理解,写出更多细节.
The code you posted here is senseless at all.
May be you should clean your datagrid before it, by setting DataSource property to null, may be something else.
It''s hard to understand, write more details.


这篇关于刷新datagridview错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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