简体   繁体   English

如何使用C#控制Datagridview中的主键

[英]How to control primary key in datagridview with c#

I am developing window c# application. 我正在开发Windows C#应用程序。 I have data entry grid view and binding data with data table. 我有数据输入网格视图,并将数据与数据表绑定。 The table from SQL database has primary key. SQL数据库中的表具有主键。 In grid view, the primary key is working in behind. 在网格视图中,主键在后面工作。 I used DefaultValuesNeeded event for primary key. 我使用DefaultValuesNeeded事件作为主键。 It is okay. 没关系。 But it is not okay when I click on cell of new row or grid view combo and input some value in some cell and delete that value. 但是当我单击新行或网格视图组合的单元格并在某个单元格中输入一些值并删除该值时,这是不可行的。 And when I move the cursor to another row, the new row in grid view is disappeared but in behind, the primary key is null and getting error primary key can't insert null into the table. 当我将光标移动到另一行时,网格视图中的新行消失了,但是在后面,主键为null,并且在发生错误时主键无法将null插入表中。 So help me please how to control primary key in grid view when I direct access to grid view. 因此,请帮助我直接访问网格视图时如何在网格视图中控制主键。 Thanks you. 谢谢。 PS I don't want to use text box or combo box and add button to add data row to grid view and I want to play mouse cursor in grid view whatever I want. PS我不想使用文本框或组合框并添加按钮以将数据行添加到网格视图,并且我想在网格视图中播放鼠标光标。 I want to direct input entry to grid view. 我想将输入条目定向到网格视图。 Thanks again. 再次感谢。

将网格视图与主键绑定为第一隐藏列,每当您尝试更新时,删除操作都会记录传递隐藏列的值,如果删除,则在DML操作成功后删除该网格视图的行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM