DataGridView的更新 [英] DataGridView Update

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

问题描述

我使用的是2005年Windows窗体在C#。我只是一直在努力,在这一天,这样下去容易吧。

I'm using 2005 Windows Forms in C#. I've only been working at this for a day, so go easy please.

我想有一个提交按钮,将更改保存到一个DataGridView。我已经得到的数据到DGV,并可以编辑,但我卡在更新()。

I'd like to have a submit button that saves changes to a DataGridView. I've gotten data into the DGV and can edit, but am stuck on the Update().

我已经创建了一个名为SCDB一个的.xsd和一个数据表叫做 - SSIS的配置升级。然后添加一个新的查询,它接受一个参数。

I've created an .xsd named scDB and one DataTable called - SSIS Configurations Staging. I then added a new query that takes a parameter.

下面是我的code到目前为止:

Here is my code so far:

//Declared at top of form class    
scDBTableAdapters.SSIS_Configurations_StagingTableAdapter myStagingTableAdapter = new scDBTableAdapters.SSIS_Configurations_StagingTableAdapter();


//After a form event            
stagingGrid.DataSource = myStagingTableAdapter.GetDataBy(filterName.Text.ToString());

//On Submit click:

myStagingTableAdapter.Update(?What Goes Here?);

什么被传递到更新的方法?我知道这需要一个DataTable,但我不知道如何引用的是在GridView。在大多数code例子人定义数据表 - 但我不知道。我认为这是正在幕后做时,我创建的TableAdapter的。感谢您的帮助。

What gets passed to the Update method? I know it needs a dataTable, but I don't know how to reference what is in the GridView. In most code examples people define the DataTable - but I do not. I assume this is being done behind the scenes when I created the TableAdapter. Thanks for the help.

推荐答案

山姆,

更新需要一个表,所以你可以尝试这样的:

the update needs a table so you could try something like:

TableType table = (TableType) stagingGrid.DataSource;
myStagingTableAdapter.Update(table);

在这里,你将不得不替换TABLETYPE适当的事情。

where you'll have to substitute TableType with something appropriate.

但更好的方法是使用拖和下降和学习构成了code。

But a better approach would be to use drag-and-drop and learn form the code.

  1. 选择数据|浏览数据源。您的 数据集应该在可见光 数据源窗口。
  2. 将一个表 (新)的形式。 VS2005将增加的负载 组件和几行 code。
  1. Select Data|View Datasources. Your dataset should be visible in the DataSources Window.
  2. Drag a table to a (new) form. VS2005 will add a load of components and a few lines of code.

窗体现在将有数据集的一个实例,这是Adapter.Fill和.Update方法的参考点。

The form will now have a instance of the dataset and that is your reference point for Adapter.Fill and .Update methods.

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

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