首先明确两点: 1. Sqlite对Guid的存储方式是将Guid以16位byte[]的形式顺序保存在数据库中。 2.C#中的Guid对象实际上就是16位byte[],但其表达方式并不是按照byte数组顺序的(具体可以查阅MSDN,这也就是为什么Guid.ToString时显示的以“-”间隔的长度不等的原因),这是导致C#和Sqlite中Guid不匹配的本质原因。 解决方法: C# to Sqlite: string sql = string.Format("select x'{0}'", BitConverter.ToString(id1.ToByteArray()).Replace("-", "")); Sqlite to C#: 假设数据库中的该字段名称为Id类型为guid,取出的数据为object o: "select Id from tb;" Guid id = (Guid)o; 假设数据库中该字段类型为blob: select Id from tb; Guid id = Guid.Parse((byte[])o);
原文地址:http://hi.baidu.com/usercontrol/item/b5c7570d4512513af3eafc34