应用程序有没有用户输入的,也不会是活在网络上,所以SQL注入是不是威胁如何更新多个SQL行,其中表1的ID等于表2的ID
我的应用程序
此应用程序应该从1个表格向Google地理编码器API发送多个地址,并将返回的纬度和经度存储在第二个表格中供以后使用。API每天最多可以处理2500个请求。
问题是什么
当我运行我的程序,没有limmits,只有几排(约20),获得更新出来,都应该得到更新2500行。当我限制我的程序只更新10行以避免触及API限制时,不会发生任何更改。我允许2500次请求时更新的大部分行都使用正确的值进行更新(除了少数几个之外),现在我不担心这一点,我认为这只是地理编码器的糟糕结果。
我有什么到目前为止
我有2串strLat和strLong持有从谷歌地理编码API检索lattitudes和经度。
string strLat = myCoordenates.Results[3].Geometry.Location.Lat.ToString();
string strLong = myCoordenates.Results[3].Geometry.Location.Lng.ToString();
我也有我的企图用他们更新我的数据库。这已经改变和操纵很多次了,我认为这个问题很可能与我的这部分代码有关。
using (SqlConnection myConnection = new SqlConnection(context))
{
myConnection.Open();
string strQueryUpdate = "UPDATE WEB_ARENA_GEO SET Lat = '" + strLat + "', Lng = '" + strLong + "'" + "WHERE ARENA_ID='" + row.ARENA_ID + "'";
SqlCommand myCommandUpdate = new SqlCommand(strQueryUpdate, myConnection);
myCommandUpdate.ExecuteNonQuery();
}
以我数据的基础上表1保持地址数据它具有PK ID以及一个称为ADDRESS_ID列,然后地址被分解等地址,城市,ST,ZIP ... ETC,表2持有纬度和经度,并且具有相同的等值的同一个ADDRESS_ID表,目前大部分的lats和lng都是0.00,它是十进制的。
表1
| --PKid-- | ADDRESS_ID |地址| CITY ..等
| 124246 | 70-00002913 | 112 bill st。 |鲍勃镇
表2
| ADDRESS_ID | Lat | Lng |
| 70-00002913 | 0.00 | 0.00 |
整个更新控制器
//GET: /TABLE2/Update/
public ActionResult Update(string id)
{
IEnumerable<TABLE1> table1 = db.TABLE1;
IEnumerable<TABLE2> table2 = db.TABLE2;
string context = "my database context here";
foreach (var row in table1.AsEnumerable().Take(10))
{
string strAddr = row.ADDRESS + "," + row.CITY + "," + row.ZIP + "," + row.COUNTRY;
GoogleMapsDll.GeoResponse myCoordenates = new GoogleMapsDll.GeoResponse();
myCoordenates = GoogleMapsDll.GoogleMaps.GetGeoCodedResults(strAddr);
if (myCoordenates.Results != null && myCoordenates.Results.Length > 3)
{
string strLat = myCoordenates.Results[3].Geometry.Location.Lat.ToString();
string strLong = myCoordenates.Results[3].Geometry.Location.Lng.ToString();
using (SqlConnection myConnection = new SqlConnection(context))
{
myConnection.Open();
string strQueryUpdate = "UPDATE WEB_ARENA_GEO SET Lat = '" + strLat + "', Lng = '" + strLong + "'" + "WHERE ADDRESS_ID='" + row.ADDRESS_ID + "'";
SqlCommand myCommandUpdate = new SqlCommand(strQueryUpdate, myConnection);
myCommandUpdate.ExecuteNonQuery();
}
db.SaveChanges();
}
}
return RedirectToAction("Index");
如果任何其他信息将是有益的,请简单地问了意见,我会尽我所能提供
我不是其所以然清楚,你不知道该怎么在这里做?它在UPDATE中使用JOIN吗? – 2014-12-04 14:32:56
你好SQL注入 – 2014-12-04 14:33:28
我需要能够更新表2中的行与正确的纬度和经度与表1中相同的ID相匹配 – RyeNyeTheComputerScienceGuy 2014-12-04 14:34:18