2013-06-12 42 views
0

您能確定我的錯誤在哪裏嗎? 當我運行此我得到一個錯誤的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(); 
+2

您是否聽說過[SQL注入](http://msdn.microsoft.com/en-us/library/ms161953(v = sql.105).aspx)? – James

+0

您有SQL注入漏洞。使所有輸入參數(它也會增加性能)。另外,對ADO.NET對象(或任何實現了「IDisposable」接口的使用塊) –

+2

您是否缺少'Values'條目中的右括號 – mfdoran

回答

5

你缺少最後的括號)除非這是一個錯字

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)"; 
                  ^
                  ^
                  ^
+0

Oh geez ....在臉上凝視着我...謝謝......這很奏效,我會盡快答覆。 – webdad3

+1

@JeffV請注意其他正確的評論SQL注入。 –

+1

我會再次感謝您的幫助! – webdad3