返回后更新datagrid [英] updating datagrid after returning

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

问题描述

点击frmSize中的btnDeleteSize_Click后,我移动到frmSizeDelete,允许

使用datagrid删除一个Size,然后返回到frmSize并想要

更新datagrid frmSize反映删除。我无法弄清楚

如何更新frmSize中的datagrid,尽管
frmSizeDelete中的datagrid正确地显示了删除。


在frmSizeDelete中,当用户单击数据网格中的行

并按下删除键时,正确删除大小:


private void frmSizeDelete_Load( object sender,System.EventArgs e)
{

strCommandText =" SELECT SizeID,SizeName FROM tblSize WHERE SizeID =''" +

strCurrentSize +"''" ;;

this.oleDbSelectCommand1.CommandText = strCommandText;

oleDbDataAdapter1.Fill(dsSizeDelete1); < br $>
}


private void frmSizeDelete_Closing(对象发送者,

System.ComponentModel.CancelEventArgs e)

{

oleDbDataAdapter1.Update(dsSizeDelete1);

}


然而,当我回到frmSize时我无法想象如何显示更新的

数据网格。

以下代码没有错误,但不起作用:


private void btnDeleteSize_Click(object sender,System.EventArgs e)

{

// dgSize.ReadOnly = false; (dgSize是readonly,显示更新这个问题吗?)

DialogResult按钮=

MessageBox.Show(你确定吗?你想删除这个尺码吗?这个尺码将从所有产品零件中删除
!!!,删除尺寸,

MessageBoxButtons.YesNo,

MessageBoxIcon.Question,

MessageBoxDefaultButton.Button2);

if(button == DialogResult.Yes)

{

表格newSizeDeleteForm = new frmSizeDelete(txtSizeID.Text);

newSizeDeleteForm.Show();

dsSize1.Clear();

oleDbDataAdapterSize.Fill(dsSize1);

oleDbDataAdapterSize.Update(dsSize1);

dgSize.Update();

dgSize。显示();


我添加了最后5个语句,希望在

frmSize中显示数据网格显示更改,我不知道如果需要它们中的任何一个,但是它们没有按预期显示变化。我该怎么办?


谢谢,

Pam

After clicking btnDeleteSize_Click in frmSize, I move to frmSizeDelete, allow
deleting a Size using a datagrid, and then return to frmSize and want to
update the datagrid in frmSize to reflect the deletion. I can''t figure out
how to get the datagrid in frmSize updated, although the datagrid in
frmSizeDelete shows the deletion properly.

In frmSizeDelete the size is properly deleted when the user clicks the row
in the datagrid and presses the delete key:

private void frmSizeDelete_Load(object sender, System.EventArgs e)
{
strCommandText = "SELECT SizeID, SizeName FROM tblSize WHERE SizeID = ''" +
strCurrentSize + "''";
this.oleDbSelectCommand1.CommandText = strCommandText;
oleDbDataAdapter1.Fill(dsSizeDelete1);
}

private void frmSizeDelete_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
oleDbDataAdapter1.Update(dsSizeDelete1);
}

However, when I return to frmSize I can''t figure out how to show the updated
datagrid.
The following code has no errors, but doesn''t work:

private void btnDeleteSize_Click(object sender, System.EventArgs e)
{
// dgSize.ReadOnly = false; (dgSize is readonly, does this matter in showing
the update?)
DialogResult button =
MessageBox.Show("Are you sure you want to delete this size? This size will
be deleted from ALL product parts!!!", "Delete Size",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (button ==DialogResult.Yes)
{
Form newSizeDeleteForm = new frmSizeDelete(txtSizeID.Text);
newSizeDeleteForm.Show();
dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);
oleDbDataAdapterSize.Update(dsSize1);
dgSize.Update();
dgSize.Show();

I added these last 5 statements in the hopes of making the datagrid in
frmSize show the change, and I don''t know if any of them are needed, but they
do not show the change as expected. What should I do?

Thanks,
Pam

推荐答案

你好Pam,


首先,我想确认一下我对你的问题的理解。从

您的描述中,我了解您需要删除一行

DataSet,将其更新为数据源并更新数据网格。如果有任何

的误解,请随时告诉我。


根据您提供的代码,我没有看到任何删除代码删除

DataSet表中的那一行。删除和刷新时,我们有2个

选项。


第一个是删除frmSize中的当前DataSet并使用

DataAdapter将其更新为数据源。由于datagrid绑定到了
DataSet,当它中的数据发生变化时,它会自动显示更改。

例如,我需要删除一行dr。


dr.Delete();

oleDbDataAdapterSize.Update(dsSize1);


第二种是直接删除数据在数据库中,然后用更新的数据重新填充

DataSet。

dsSize1.Clear();

oleDbDataAdapterSize。填写(dsSize1);


HTH。


Kevin Yu

=======

"提供此帖子按现状没有保证,并且没有赋予

权利。

Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to delete a row of the
DataSet, update it to data source and update the data grid. If there is any
misunderstanding, please feel free to let me know.

Based on the code you have provided, I didn''t see any delete code to delete
that row in the DataSet table. When deleting and refreshing, we have 2
choices.

The first is to delete in the current DataSet in frmSize and use an
DataAdapter to update it to the data source. Since the datagrid in bound to
DataSet, when data in it changes, it will automatically show the changes.
For example, I need to delete a row dr.

dr.Delete();
oleDbDataAdapterSize.Update(dsSize1);

The second is to delete data directly in the database and then re-fill the
DataSet with updated data.

dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


谢谢,但这并没有帮助,因为它已经是我在做什么了。它仍然无法工作。


为了回答你的问题,我使用了datagrid内置的功能来删除

行 - 用户突出显示该行并按下删除。那部分工作正常。它

还显示frmSizeDelete中dgSizeDelete中的删除罚款。当我返回到调用表单,frmSizes并希望DataGrid,dgSize,在

中调用表单来更新我有问题时,它是




从我的初始帖子中可以看出,

dsSize1.Clear();

oleDbDataAdapterSize.Fill(dsSize1);

正是我所做的。当我回到它时,dgSize没有显示frmSize的变化。这就是为什么我在它之后添加了3行代码来试图获得数据网格来显示更改。


我刚试了一次,评论超出3行代码。它b / b
仍然无法工作。


我认为你不明白的是你的代码示例不是
我遇到问题的
datagrid,这是我回到

的数据网格,这是一个问题的调用表格。


Pam


" Kevin Yu [MSFT]"写道:
Thank you, but this didn''t help since it is already what I am doing. It
still doesn''t work.

To answer your question, I used the datagrid built in features to delete the
row - user highlights the row and presses delete. That part works fine. It
also shows the deletion fine in the dgSizeDelete in the frmSizeDelete. It is
when I return to the calling form, frmSizes and want the Datagrid, dgSize, in
the calling form to update that I have a problem.

As you can see from my initial post,
dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);
is exactly what I did. And dgSize did not show the change in frmSize when I
return to it. This is why I added the 3 lines of code after it to try to get
the datagrid to show the change.

I just tried it again, commenting out the 3 additional lines of code. It
still doesn''t work.

What I think you don''t understand is that your example of code is not the
datagrid that I am having a problem with, it is the datagrid I return to in
the calling form that is a problem.

Pam

"Kevin Yu [MSFT]" wrote:
嗨帕姆,

首先,我想确认一下我对你的问题的理解。从
您的描述中,我了解到您需要删除一行数据集,将其更新为数据源并更新数据网格。如果有任何误解,请随时告诉我。

根据您提供的代码,我没有看到删除任何删除代码
DataSet表中的行。删除和刷新时,我们有2个选择。

第一个是删除frmSize中的当前DataSet并使用
DataAdapter将其更新为数据源。由于datagrid绑定到DataSet,当它中的数据发生变化时,它会自动显示变化。
例如,我需要删除一行博士。

博士。删除();
oleDbDataAdapterSize.Update(dsSize1);

第二种是直接在数据库中删除数据,然后用更新的数据重新填充
DataSet。 />
dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);

HTH。

Kevin Yu
=== ====
此帖子是按原样提供的没有保证,也没有授予
权利。
Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to delete a row of the
DataSet, update it to data source and update the data grid. If there is any
misunderstanding, please feel free to let me know.

Based on the code you have provided, I didn''t see any delete code to delete
that row in the DataSet table. When deleting and refreshing, we have 2
choices.

The first is to delete in the current DataSet in frmSize and use an
DataAdapter to update it to the data source. Since the datagrid in bound to
DataSet, when data in it changes, it will automatically show the changes.
For example, I need to delete a row dr.

dr.Delete();
oleDbDataAdapterSize.Update(dsSize1);

The second is to delete data directly in the database and then re-fill the
DataSet with updated data.

dsSize1.Clear();
oleDbDataAdapterSize.Fill(dsSize1);

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."



嗨Pam,


显示dsSize1的dataGrid没有更新,因为当你调用

newSizeDeleteForm.Show();时,你假设这行后面的代码将是

被暂停他们将等待newSizeDeleteForm关闭,更新

数据库并继续执行更新的值。


实际上,代码并没有暂停。它在newSizeDeleteForm

有机会删除数据库中的数据之前下降,这意味着它们我们运行在两个

线程中。我建议你使用newSizeDeleteForm.ShowDialog()代替

newSizeDeleteForm.Show()。这可能会帮助你摆脱困境。


Kevin Yu

=======

"这个帖子原样是按原样提供的。没有保证,也没有赋予

权利。

Hi Pam,

The dataGrid which show dsSize1 doesn''t get updated, because when you call
newSizeDeleteForm.Show();, you assume that the code behind this line will
be suspended. They will wait for the newSizeDeleteForm to close, update the
database and continue executing with updated values.

Actually, the code didn''t suspend. It goes down before newSizeDeleteForm
got a chance to delete data on the database, which mean they we run in two
threads. I suggest you to use newSizeDeleteForm.ShowDialog() instead of
newSizeDeleteForm.Show(). That might help you out of the problem.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


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

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