“列'ID'不允许空值”从datagridview抛出异常 [英] "Column 'ID' does not allow nulls" exception throw from datagridview

查看:138
本文介绍了“列'ID'不允许空值”从datagridview抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 


在SQL Server中,我创建了一个名为"CodeType"的表,其中包含以下主列:




    • ID,相同,默认值= newid(),不允许null,主键

    • Name,varchar(255),不允许null

在Visual Studio 2005中,我创建了一个数据集(xsd文件),并拖动表" CodeType"从工具栏"到服务器资源管理器"。并将列ID设置为readonly = true,allownull = true。


然后我创建一个窗体并从前面的数据集中插入一个datagridview控件。




    • 列ID是只读的。

    • 允许插入和更新。

我希望让SQL Server帮助创建ID列的值。当我测试它时,出现错误"列'ID'不允许空值"。


 


稍后我更新数据集(xsd文件)的"插入"命令,然后再试一次,错误仍然存​​在。


 


您能帮忙解决这个问题吗?


谢谢,


Phlics

解决方案

嗨全部,


我在SQL服务器中创建了一个表,并且有一个名为"ID"的列,其类型为guid,默认值为newid()。此列也已设置为表的主键。


我还在前面的表格中在Visual Studio 2005中创建了一个类型化的数据集,然后在windows窗体中,使用datagridview控件向它显示和添加新记录(将ID列设置为只读) ,我希望SQL Server帮助设置ID列的值)。但是当我测试它时,在插入新记录之后,系统总是抛出异常来说明ID不能为空。


你能帮我解决这个问题吗?


 


谢谢,


 


Phlics


 

Hi ,

In SQL Server , I create a table named "CodeType" with following main column:

    • ID , identical , default value = newid() , not allow null , primary key
    • Name, varchar(255) , not allow null

In Visual Studio 2005 , I create a dataset (xsd file) , and drag the Table "CodeType" to it from toolbar "Server Explorer". And set the column ID as readonly = true , allownull = true.

Then I create a windows form and insert a datagridview control from preceding dataset.

    • Column ID is read only .
    • Allow insert and update .

My hope is to let SQL Server help to create the value for ID column. When I test it , the error "Column 'ID' does not allow nulls" appear.

 

Later I update the "Insert" command of the dataset(xsd file) and try again, the error still occur.

 

Would you please help to address the issue ?

Thanks,

Phlics

解决方案

Hi All,

I created a table in SQL server and there is a column named "ID" which type is guid and default value is newid(). This column also been set to primary key of the table.

I also created a typed dataset in Visual Studio 2005 from preceding table , then in a windows form , used datagridview control to show and add new record to it(set the column of ID to readonly, I hope SQL Server help to set the value of ID column). But when I test it , after inserting a new record , the system always throw exception to say that the ID can not be null.

Would you please help me to address the issue ?

 

Thanks,

 

Phlics


这篇关于“列'ID'不允许空值”从datagridview抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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