Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite选择GUID中id所在的位置_C#_Sql_Sqlite_Xamarin - Fatal编程技术网

C# SQLite选择GUID中id所在的位置

C# SQLite选择GUID中id所在的位置,c#,sql,sqlite,xamarin,C#,Sql,Sqlite,Xamarin,因此,我试图从一个表中选择所有值,其中Id在value、value1、value2中 其中value是类型Guid 使用这个答案: 我创建了以下Sql语句: Select * from [Imaging.ImageTag] where ImageId in (X'b06783c2-da62-4292-8bdc-f7915c00b2db', X'9bc10d55-661b-4530-b224-3fe32651cb74', X'

因此,我试图从一个表中选择所有值,其中Id在value、value1、value2中

其中value是类型Guid

使用这个答案:

我创建了以下Sql语句:

Select *
from [Imaging.ImageTag]
where ImageId in (X'b06783c2-da62-4292-8bdc-f7915c00b2db',
                  X'9bc10d55-661b-4530-b224-3fe32651cb74',
                  X'0404c0c1-65a0-4913-9e36-fd9d3e129783',
                  X'cd41ac25-9b75-4d14-bd6b-38e56013020a',
                  X'122014a5-f8bd-4c0b-8c95-b9eec4b60e7e',
                  X'fa4bad5d-42b2-40fa-bf78-4942f29f6355',
                  X'3938b974-d174-4492-9d3b-68733bef9a14',
                  X'b8ac27c4-125f-4fa9-bc91-c6c7fb83c33c',
                  X'0e10bd73-4254-4614-a112-031ce0a3d526',
                  X'd2979e7c-1cb0-40cb-9898-c57d2f4a083a',
                  X'04251d49-9cd8-40d8-9c43-a17a325ddd4b',
                  X'44e56e78-94ce-4308-815d-7d95acae6904',
                  X'481c95d1-52f7-4331-a0f0-a2754dba87f5'
                 )
但我得到了一个错误:

无法识别的令牌:X'b06783c2-da62-4292-8bdc-f7915c00b2db'

好吧,我知道了

Sqlite中没有Guid这样的东西,因此它存储为blob。这意味着,当您试图查询给定的Guid时,需要将Guid转换为Guid的十六进制字符串表示形式,即字节数组

要在C中执行此操作,我有以下代码:

query = string.Format("Select * from [TableName] where ImageId in (x'{0}')", string.Join("',x'", ids.Select(x => SqliteDatabaseExtensions.ByteArrayToString(x.ToByteArray())));
其中ids是一个列表

其中重要的一点是:

SqliteDatabaseExtensions.ByteArrayToString(new Guid(x.ToString()).ToByteArray())
其中,静态方法为:

private static string ByteArrayToString(byte[] ba)
{
    StringBuilder hex = new StringBuilder(ba.Length * 2);
    foreach (byte b in ba)
        hex.AppendFormat("{0:x2}", b);
    return hex.ToString();
}

如果删除-symbols,是否有效?ie:X'b06783c2da6242928bdcf7915c00b2db'@Igor我认为可能是它,但我测试了它,它返回了0行。虽然它没有抛出异常,但看起来不起作用。如果它返回0行,并且没有产生错误,那么这是正确的语法,但是列表中没有匹配项。我知道这些GUI有行。我会不断地用我的头撞击它,如果我发现任何东西,请告诉你,你必须知道这些值实际上是以什么格式存储的。从ImageTag中选择typeofImageId、maxImageId的输出是什么?当您有一个字节数组时,您可以直接将其用作blob参数。任何仍在挣扎的人,请记住它的X而不是X。