我喜欢在查询下面运行:
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次相同的参数及其值
参数("?")::: value(ex.12345)
我在下面写了代码,但只有一次参数。
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();
你可以看到我尝试过一些逻辑,但它们并不能满足我的要求。 如何在我的逻辑命令中添加参数数组?
答案 0 :(得分:0)
在SQLite中,您可以明确地给parameters一个数字:
... WHERE x = ?1 OR y = ?1 AND z <> ?1 ...
或给它起个名字:
... WHERE x = :PoiID OR y = :PoiID AND z <> :PoiID ...