无法使用Winforms中的C#使用datagridview添加新行 [英] unable to add new row using datagridview using C# in Winforms

查看:169
本文介绍了无法使用Winforms中的C#使用datagridview添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个简单的数据录入应用程序。所以我做了以下




  • 创建了一个新的Windows窗体应用程序

  • 添加了一个DataGridView

  • 添加了一个新的DataSource(SQL Express数据库,具有3列的单个表 - id,name,number)id是整数,是主键

  • 当设计器自动填充DataSet时,BindingSource和TableAdapter我运行应用程序。当我运行应用程序显示现有数据时,



我可以通过点击空行或编辑现有数据来添加新数据。但它没有存储(提交)数据给我。



在我进行更改后,我只需关闭应用程序。我记得前一段时间曾经这样做,它反映了变化。我必须添加任何代码来提交更改吗?

解决方案

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


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

  • Created a new Windows Form Application
  • Added a 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
  • As the designer automatically populates the DataSet, BindingSource and TableAdapter i ran the application.

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?

解决方案

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).

这篇关于无法使用Winforms中的C#使用datagridview添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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