一个数据表中有一个字段id的类型为uniqueidentifier,而且Is 
RowGuid设置为yes,但这个表插入数据时出现错误,提示id不能为空值,按道理id的值应该是插入数据时在服务器里生成的,请问怎样才能往包含uniqueidentifier而且is rowguid设置为yes的表插入数据?
我试过用数据窗体向导生成程序,也不能输入数据,还是提示id不能为空值。

解决方案 »

  1.   

    what database are you using? if it is sql server, you could assign it a default value with newid() function likecust_id uniqueidentifier NOT NULL DEFAULT newid()
      

  2.   

    是啊,使用SQL Server,已经设置默认值为newid()。
      

  3.   


    when you insert data, don't include that guid column in the list, for exampleCREATE TABLE cust
    (
     cust_id uniqueidentifier NOT NULL
       DEFAULT newid(),
     company varchar(30) NOT NULL)
    insert into cust (company) values ('123')select * from custor show your code
      

  4.   

    这样设置后就像identity一样,它会自动产生的,一般不会出现问题,莫非你的insert的sql语句有问题,贴出来看看
      

  5.   

    你可能还需要设置id字段的increase那个属性,让他自动增加1.
      

  6.   

    回复人: cdo(VC?我才刚学) ( ) 信誉:100  2005-09-07 08:36:00  得分: 0  
     
     
       你可能还需要设置id字段的increase那个属性,让他自动增加1.
      
     
    -------------------------------------------???这个newid()还用+1德说?估计是lz把guid的那个字段给写在sql语句里面了
      

  7.   

    顺便看看是不是有什么trigger在添乱 :-s
      

  8.   

    什么数据库啊?
    SQLServer用newid()
    其他我就不知道了.
      

  9.   

    大家可以帮忙测试一下,在SQL里建一个表,含两个字段,一个是uniqueidentifier,而且Is
    RowGuid设置为yes,也就是DefaultValue是newid(),另一个是char(10)类型,然后用Visual Studio .NET 22003的数据窗体向导生成一个含有这个表的数据窗体,就会出现问题。也就是说微软自己也搞不掂这个问题。