尽管标识列设置为自动递增,但将数据插入到 datagridview 时出现 NoNullAllowedException 错误

发布于 2024-09-12 15:21:19 字数 284 浏览 2 评论 0原文

我在我的程序中放置了一个DataGridView,使得这个DataGridView对应于一个表的数据集,并且该表有一个自动递增的标识列(同时,该列被设置为主键)。

此标识列在 DataGridView 中不可见,并且当用户填充其他单元格并单击“保存”时,会发生NoNullAllowedException

为什么?我想让用户只插入数据(而不是其他修改)

我该怎么办?我使用 C# 和 SQL server 2008

干杯

I have put a DataGridView in my program such that this DataGridView is corresponding to a dataset of one table and this table has a auto-incremented identity column(also,this column is set to be primary key).

This identity column is not visible in DataGridView and when a user fills other cells and clicks "save",NoNullAllowedException occurs.

Why?I want to allow user to just insert data(not another modification)

How can I do?I use C# and SQL server 2008

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一刻暧昧 2024-09-19 15:21:19

你的目标表定义是什么?是否有任何列具有 NOT NULL 限制?

What's your target table definition? Does any column have the NOT NULL restriction?

姜生凉生 2024-09-19 15:21:19

查看您的表并找到所有不为 NULL 的列,并确保表单将某些内容发布到这些字段中。

如果确实只是主键导致了问题,请通过使用 T-SQL 代码(INSERT INTO)等直接从 SQL Server Management Studio 发布数据来验证它是否有效。

Look at your table and find all the columns that are NOT NULL and make sure the form is posting something into those fields.

If it really is just the Primary Key that's causing the issue verify that it works by posting data directly from SQL server management studio with T-SQL Code (INSERT INTO) etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文