尽管标识列设置为自动递增,但将数据插入到 datagridview 时出现 NoNullAllowedException 错误
我在我的程序中放置了一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的目标表定义是什么?是否有任何列具有
NOT NULL
限制?What's your target table definition? Does any column have the
NOT NULL
restriction?查看您的表并找到所有不为 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.