在编辑/删除/添加时,DataGridView如何将内容保存到数据库中 [英] How does DataGridView saves things to a database when editing/deleting/adding

查看:80
本文介绍了在编辑/删除/添加时,DataGridView如何将内容保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Entity Framework 6,我有一个DataGridView。此外,我已禁用直接在网格视图上添加,删除和编辑行,因为我只想将它用于显示数据(我想使用我的表单来更新/添加行)。我有一个
表单,其中包含绑定到绑定源的文本框。


此外,网格视图还设置了数据源,当我在表单上的文本框中输入内容时,网格视图会受到这些更改以及数据库的影响(如果我是正确的)。我想知道如果我没有执行
context.Save(),有人可以解释保存的时间吗?例如,如果我通过我的表单添加一行(使用myBindingSource.AddNew()方法,这是否仅将实体添加到绑定源,并且该更改仅显示在网格视图中,或者是否持久保存到数据库中?


如果它持续存在,如果我不是那个调用context.Save()的人会怎么样?抱歉由于缺乏细节,我可以编辑我的问题来改进它,如果有更多细节的话需要。

解决方案

您好,


您可能会在我的MSDN中找到您的一些答案代码示例。我没有使用与DataGridView相切的TextBox控件,而是使用模态对话框窗口添加和编辑,而删除是通过BindingNavigator使用带有确认的自定义按钮。


Windows中的实体框架构成第4部分


屏幕截图



I am using Entity Framework 6 and I have a DataGridView. Also I have disabled adding, deleting and editing of rows directly on the grid view because I want to use it only for displaying data (and I want to use my form for updating/adding rows). I have a form that have textboxes which are bound to binding sources.

Also the grid view has its datasource set, and when I enter something in a textbox found on my form, a grid view is affected with those changes, as well as database (if I am correct). I wonder if somebody can explain when saving happens if I didn't executed context.Save() ? For example, if I add a row through my form (using myBindingSource.AddNew() method ,does this add entity only to a binding source, and that change is only shown in a grid view, or this is persisted into a database ?

If it persisted, how this happen if I am not the one who calls context.Save() ? Sorry for the lack of details, I could edit my question to improve it, if more details are needed.

解决方案

Hello,

You might find some of your answers in my MSDN code sample. I'm not using TextBox controls in tangent with the DataGridView but instead use a modal dialog window to add and edit while delete is via the BindingNavigator using a custom button with confirmation.

Entity Framework in Windows forms part 4

Screen shot


这篇关于在编辑/删除/添加时,DataGridView如何将内容保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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