您能確定我的錯誤在哪裏嗎? 當我運行此我得到一個錯誤的ExecuteNonQuery
「@geoPoint」附近的語法不正確
附近有語法錯誤@geoPoint「
sqlConnection.Open();
string commandText = "INSERT INTO shapefileTest (state, nrng, twp, lgnt, type, ntwp, meridian, rdir, tdir, rng, stcty, county, shape) VALUES ('" + state + "', '" + nrng + "', '" + twp + "' , " + lgnt + ", '" + type + "', '" + ntwp + "', '" + meridian + "', '" + rdir + "', '" + tdir + "', '" + rng + "', '" + stcty + "', '" + county + "', @geoPoint";
SqlCommand sqlComm = new SqlCommand(commandText, sqlConnection);
SqlParameter param = new SqlParameter();
param.ParameterName = "@geoPoint";
param.UdtTypeName = "Geography";
param.Value = sqlGeog;
sqlComm.Parameters.Add(param);
sqlComm.ExecuteNonQuery();
sqlConnection.Close();
您是否聽說過[SQL注入](http://msdn.microsoft.com/en-us/library/ms161953(v = sql.105).aspx)? – James
您有SQL注入漏洞。使所有輸入參數(它也會增加性能)。另外,對ADO.NET對象(或任何實現了「IDisposable」接口的使用塊) –
您是否缺少'Values'條目中的右括號 – mfdoran