无法在Winforms中使用C#使用datagridview添加新行

时间:2021-06-14 20:55:08

i wanted to make a simple data entry application. So i did the following

我想制作一个简单的数据输入应用程序。所以我做了以下事情

  • Created a new Windows Form Application
  • 创建了一个新的Windows窗体应用程序

  • Added a DataGridView
  • 添加了DataGridView

  • Added a new DataSource (SQL Express Database, having a single table with 3 columns - id, name, number) id is integer and is the primary key
  • 添加了一个新的DataSource(SQL Express数据库,具有3列的单个表 - id,name,number)id是整数并且是主键

  • As the designer automatically populates the DataSet, BindingSource and TableAdapter i ran the application.
  • 当设计器自动填充DataSet时,BindingSource和TableAdapter运行了应用程序。

when i ran the application it showed the existing data, and i was able to add new data by clicking on empty row or edit existing data. But it did not store (commit) the data for me.

当我运行应用程序时,它显示了现有数据,我可以通过单击空行或编辑现有数据来添加新数据。但它没有为我存储(提交)数据。

After i make the changes i just close the application. I remember doing it some time ago and it used to reflect changes. Do i have to add any code to commit the changes?

在我做出更改之后,我就关闭了应用程序。我记得前一段时间这样做,它曾用于反映变化。我是否必须添加任何代码才能提交更改?

2 个解决方案

#1


A dataset is (by definition) disconnected. If you want to commit new data / updates / deletes (etc), you are going to have to ask the adapter to save the changes. If you already have a generated adapter, this should be about 1 line of extra code... (Update on the adapter, usually via a save button's Click handler).

数据集(根据定义)已断开连接。如果要提交新数据/更新/删除(等),则必须要求适配器保存更改。如果你已经有一个生成的适配器,这应该是大约1行的额外代码...(在适配器上更新,通常通过保存按钮的Click处理程序)。

#2


Insert Update Delete using datagrid

使用datagrid插入更新删除

#1


A dataset is (by definition) disconnected. If you want to commit new data / updates / deletes (etc), you are going to have to ask the adapter to save the changes. If you already have a generated adapter, this should be about 1 line of extra code... (Update on the adapter, usually via a save button's Click handler).

数据集(根据定义)已断开连接。如果要提交新数据/更新/删除(等),则必须要求适配器保存更改。如果你已经有一个生成的适配器,这应该是大约1行的额外代码...(在适配器上更新,通常通过保存按钮的Click处理程序)。

#2


Insert Update Delete using datagrid

使用datagrid插入更新删除