在SQLitecommand中多次传递相同的参数 [英] Pass same parameters multiple times in SQLitecommand
本文介绍了在SQLitecommand中多次传递相同的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我喜欢在查询下面运行:
I like to run below query :
select
lon, lat
from rdf_city_poi p, rdf_location l
where p.location_id = l.location_id and p.poi_id = ?
union all select
lon, lat
from rdf_poi_address p, rdf_location l
where p.location_id = l.location_id and p.poi_id = ?
union all select
lon, lat
from xtdp_poi_address pa, xtdp_location l
where pa.location_id=l.location_id and pa.poi_id= ?
如您所见,它是相同参数的3倍,并且是值
As you can see it's required 3 times same parameter and it's value
参数(?"):::值(例如12345)
我在下面的代码中编写了一个参数,但只有1次.
I have written below code which take argument but only 1 time.
int Carto_id = Convert.ToInt32(dtsqlquery2.Rows[k][0]);
string selectpoly = xNodelatlongquery2.Replace("\r\n", string.Empty);
//SQLiteCommand selectpolygon = new SQLiteCommand(selectpoly + Carto_id, con);
int countparameters = selectpoly.Split('?').Length - 1;
SQLiteCommand selectpolygon = new SQLiteCommand(selectpoly, con);
//var paramaters = new string[countparameters];
//SQLiteParameter[] parameters = new SQLiteParameter[countparameters];
for (int i = 0; i < countparameters; i++)
{
//SQLiteParameter[] parame = new SQLiteParameter[]{
//new SQLiteParameter("?", Carto_id)};
//paramaters[i] = string.Format("?", Carto_id);
//selectpolygon.Parameters.AddWithValue(paramaters[i], Carto_id);
selectpolygon.Parameters.AddWithValue("?", Carto_id);
}
//selectpolygon.Parameters.AddRange(paramaters);
SQLiteDataReader dataReaderpoly = selectpolygon.ExecuteReader();
DataSet ds1 = new DataSet();
您可以看到我已经尝试了一些逻辑,但是它们不满足我的要求. 如何在我的逻辑命令中添加参数数组?
You can see I have tried with some logics but they are not satisfying my requirement. How can I Add array of parameters into command of my logic ?
推荐答案
在SQLite中,您可以给参数一个明确的数字:
In SQLite, you can give parameters a number explicitly:
... WHERE x = ?1 OR y = ?1 AND z <> ?1 ...
或为其命名:
... WHERE x = :PoiID OR y = :PoiID AND z <> :PoiID ...
这篇关于在SQLitecommand中多次传递相同的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文