如何使gridview中的第一列独立或在C#中使其成为身份 [英] How make first column in gridview sit alone or make it identity in C#

查看:80
本文介绍了如何使gridview中的第一列独立或在C#中使其成为身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了gridview,我希望单独创建第一列网站编号,或者在我完成在此网格中的每一行中插入数据后,使其成为数据库中的标识。



我尝试了什么:



如何在C#申请表格中使用gridveiw

i create gridview and i want make first column site number alone or make it identity like in database after i finish insert data in every row in this grid.

What I have tried:

How i do that in gridveiw in C# application form

推荐答案

如果您的数据库中的列是IDENTITY,那么您不想编辑它,影响它或将任何值放入其中 - 数据库会在您尝试时抱怨,因为您不允许写入IDENTITY领域。同样,即使它们没有进入数据库,也不应在网格中创建标识值 - 只有在保存值并将其提交到永久存储中时才应创建标识值。做任何其他事情都是危险的 - 它总会以缺失或重复的值结束,而这实际上会使您的数据混乱,直到它根本无法被信任。这可能不会立即发生,但它会发生 - 经常在对代码的无关部分进行少量修改之后。



所以忘记它在网格中 - 分配ID仅限永久存储。
If your column in the DB is IDENTITY, then you do not want to edit it, affect it, or put any values into it - the database will complain when you try as you are not allowed to write into an IDENTITY field. Similarly, you should not create identification values in a grid even if they are not going into a DB - they should be created only when the values are saved and committed into permanent storage. To do anything else is dangerous - it will always end up with "missing" or "duplicated" values and that really messes your data up to the point it can't be trusted at all. That may not happen immediately, but it will happen - often after a small modification to an "unrelated" part of the code.

So forget it in the grid - assign ID's when it goes to permanent store only.


这篇关于如何使gridview中的第一列独立或在C#中使其成为身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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