zoukankan      html  css  js  c++  java
  • 如何解决:将字符串转换为 uniqueidentifier 时出现语法错误 (转载)

    原文出处:http://www.cnblogs.com/advance/archive/2006/07/04/442651.html

    项目编译时出现以下错误:

    将字符串转换为 uniqueidentifier 时出现语法错误。
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.Data.SqlClient.SqlException: 将字符串转换为 uniqueidentifier 时出现语法错误。

    源错误:


    行 110:FDataSet = new DataSet();
    行 111:if (init_sql.Length>0)
    行 112:FDataAdapter.Fill(FDataSet);
    行 113:
    行 114:}

    究其原因,得出以下结论:

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

    string guid=System.Guid.NewGuid().ToString();//或System.Guid.Empty.ToString();

    System.Guid g=new Guid(guid);//给数据库字段赋值时转换为guid类型

    或者不要定义成string类型的,直接定义成guid类型的,如

    public static readonly string ZeroUniqueID="{00000000-0000-0000-0000-000000000000}";// 代表一个不存在的编号
    改为
    public static readonly Guid ZeroUniqueID=System.Guid.Empty;// 代表一个不存在的编号
    这样就可以直接给数据库字段赋值了,不用做任何的转换。
  • 相关阅读:
    topcoder srm 320 div1
    topcoder srm 325 div1
    topcoder srm 330 div1
    topcoder srm 335 div1
    topcoder srm 340 div1
    topcoder srm 300 div1
    topcoder srm 305 div1
    topcoder srm 310 div1
    topcoder srm 315 div1
    如何统计iOS产品不同渠道的下载量?
  • 原文地址:https://www.cnblogs.com/purplefox2008/p/1359928.html
Copyright © 2011-2022 走看看