INSERT INTO Class_GradePoint(classID,classScore)
VALUES('bc600a9-4fa4-4bc4-88a9-0dd8d57f0076','3')消息 8169,级别 16,状态 2,第 1 行
将字符串转换为 uniqueidentifier 时失败。
怎么改呢,我要在数据库中测试

解决方案 »

  1.   

    INSERT INTO Class_GradePoint(classID,classScore) 
    VALUES(NEWID(),'3') 
      

  2.   

    恩,楼上的就可以.
    newid()是数据库里生成GUID的方法
      

  3.   

    是由于参数类型和数据库字段类型不一致造成的,数据库字段类型是uniqueidentifier ,而程序中参数类型是string,需要转换.
      

  4.   

    这个不能是NEWID 因为这个ID是别的表的我要把别的表的ID引用过来所以这样不行的
      

  5.   


    INSERT INTO Class_GradePoint(classID,classScore) 
    VALUES(NEWID(),'3') 可以
    如果在程序中就这样处理string guid=System.Guid.NewGuid().ToString();//或System.Guid.Empty.ToString();
    System.Guid g=new Guid(guid);//给数据库字段赋值时转换为guid类型
      

  6.   

    newid()他不就是在数据库中自动生成的吗? 默认值为Newid()
      

  7.   

    cast(字段   as   uniqueidentifier)
      

  8.   

    uniqueidentifier 数据类型不会按照 IDENTITY 属性的方式为插入的行自动生成新的 ID。例如,若要获取新的 uniqueidentifier 值,则表必须具有指定 NEWID 函数或 NEWSEQUENTIALID 函数的 DEFAULT 子句,或 INSERT 语句必须使用 NEWID 函数。 
    INSERT INTO Class_GradePoint(classID,classScore) value(newid(),'3')
    也可以
    INSERT INTO Class_GradePoint(classScore) value('3')
      

  9.   

    INSERT INTO Class_GradePoint(classID,classScore)
    VALUES(cast('bc600a9-4fa4-4bc4-88a9-0dd8d57f0076'  as  uniqueidentifier),'3')消息 8169,级别 16,状态 2,第 2 行
    将字符串转换为 uniqueidentifier 时失败。
      

  10.   

    看来你想插入自己的GUID是不可能的,除非数据表是一个varchar
      

  11.   

    INSERT INTO Class_GradePoint(classID,classScore)
    VALUES(cast('bc600a9-4fa4-4bc4-88a9-0dd8d57f0076'  as  uniqueidentifier),'3')消息 8169,级别 16,状态 2,第 2 行
    将字符串转换为 uniqueidentifier 时失败。
    ------------------
    这种方法是可以的,不过 你的BC600A9-4FA4-4BC4-88A9-0DD8D57F0076 是怎么得到的啊?这不是数据库
    uniqueidentifier 的格式标准格式:24284DF9-7A8A-4EBF-B267-F32208F57F50
    你的格式:BC600A9-4FA4-4BC4-88A9-0DD8D57F0076
      

  12.   

    复制时少复制了一个 THANK YOU