c# - 根据 Msdn GridView.DataKeyNames 必须设置,如果我们想更新数据库

标签 c# asp.net gridview ado.net

Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source. You must set the DataKeyNames property in order for the automatic update and delete features of the GridView control to work.

a) 根据上面的引述,只有设置了 DataKeyNames 才能进行更新,但即使我没有设置 DataKeyNames,我也能够更新数据库。


b) 还是自动更新这个词还有别的意思?


谢谢

最佳答案

GridView 或 Formview 可以支持自动更新,前提是它与某种正确配置的*数据源(ObjectDataSource、SqlDataSource 等)一起使用。对于删除/更新操作,需要唯一键,因此需要 DataKeyNames 集合。例如,如果数据源是强类型数据集,它会自动开箱即用。

关于c# - 根据 Msdn GridView.DataKeyNames 必须设置,如果我们想更新数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/937197/

相关文章:

c# - .Net 中有关 Google Drive 的错误

c# - 如何在 c# 中以编程方式为 Windows Mobile 6.0 设备获取 MAC 地址

asp.net - 无法加载文件或程序集 kre-clr-win - 如何指定 KRE?

LINQ OrderBy 字符串参数

asp.net - 以编程方式将 ASP.Net GridView 列设置为按钮字段

c# - XSD.exe 和 "Circular Group references"

c# - 如何正确使用列表框项目模板/数据模板中的按钮?

asp.net - 您有免费的 .Net 托管代码用于将 DocX 转换为 PDF 吗?

c# - 不同角色的表单例份验证?

c# - Devexpress gridView上下文菜单项点击