删除sqlite中的where in子句 [英] Delete where in clause in sqlite
问题描述
我在 Xamarin Forms 中使用的 sqlite 中有以下查询.
I have the following queries in sqlite which I am using in Xamarin Forms.
allProdsId
初始化为:
allProdsId = new List<Products>();
首先,我进行了一个查询,它从产品表中检索所有产品 ID.然后我想删除所有订单有 ProdId
检索到的所有 allProdsId
的订单.
First of all, I made a query which retrieves all products ID from the table products. Then I want to delete all orders where orders have ProdId
all the allProdsId
retrieved.
删除查询不起作用.有人可以帮助我使用 xamarin 形式在 sqlite 中实现 WHERE IN
子句吗?
The delete query is not working. Can someone please help me to achieve the WHERE IN
clause in sqlite using xamarin forms ?
allProdsId = _con.Query<Products>("Select ProdId from Products");
con.Execute("DELETE FROM Orders WHERE ProdId = ?", allProdsId);
推荐答案
为您希望删除的所有 ProdId 制作一个逗号分隔的字符串,并将其直接插入到 SQL 字符串中.
Make a comma separated string of all the ProdIds that you wish to delete and insert that directly into the SQL string.
var productIDs = conn.Query<Products>("Select ProdId from Products");
var prodIDCommaString = string.Join(",", productIDs.Select(p => p.ProdId));
var deleteCount = conn.Execute("delete from Products where ProdId in (" + prodIDCommaString + ");");
这篇关于删除sqlite中的where in子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!