在SQLITE命令中多次传递相同的参数
我喜欢运行以下查询:在SQLITE命令中多次传递相同的参数,sqlite,system.data.sqlite,sqlparameter,Sqlite,System.data.sqlite,Sqlparameter,我喜欢运行以下查询: 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 a
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倍
参数(“?”)::值(例如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();
int Carto_id=Convert.ToInt32(dtsqlquery2.Rows[k][0]);
string selectpoly=xNodelatlongquery2.Replace(“\r\n”,string.Empty);
//SQLITECOMAND selectpolygon=新SQLITECOMAND(selectpoly+Carto\U id,con);
int countparameters=selectpoly.Split(“?”).Length-1;
SQLITECOMAND selectpolygon=新SQLITECOMAND(selectpoly,con);
//var paramaters=新字符串[countparameters];
//SQLiteParameter[]参数=新SQLiteParameter[countparameters];
对于(int i=0;i
你可以看到,我尝试了一些逻辑,但它们不能满足我的要求。
如何将参数数组添加到逻辑的命令中?在SQLite中,您可以明确给出一个数字:
... WHERE x = ?1 OR y = ?1 AND z <> ?1 ...
。。。其中x=?1或y=?1和z?1。。。
或者给它起个名字:
... WHERE x = :PoiID OR y = :PoiID AND z <> :PoiID ...
。。。其中x=:poid或y=:poid和z:poid。。。