c#
2013-03-26 125 views -2 likes 
-2

我在執行下面的代碼時遇到問題(語法錯誤)。請幫我,我該怎麼做。謝謝。C#中的SQL select語句

表列:pId, pAltId, pMobile, pDate, pName

變量:argID, alt_ID, p_mobile, p_date, p_Name

聲明:

String selectStr = "select * from " + thisTable + " where pId = '" + argID "+ OR + 
pAltId = " + alt_ID "+ OR + pMobile =" + p_mobile "+ OR + pDate =" + p_date "+ OR + 
pName = "+ p_Name "'"; 
+1

什麼樣的問題呢? – 2013-03-26 22:40:42

+1

一個字:[**佔位符**](http://bobby-tables.com/csharp.html) – 2013-03-26 22:42:35

+0

不確定你的問題是什麼! – 2013-03-26 22:45:17

回答

1

+ " where pId = '" + argID "+應的PID值是單引號或不?你有一個開始,但沒有結局。

此外,您似乎錯過了一些雙引號,或者將它們放在錯誤的位置,缺少一些空格,並且缺少pName的起始位置。 嘗試:

String selectStr = "select * from " + thisTable + " where pId = " + argID + " " 
    + OR + " pAltId = " + alt_ID + " " + OR + " pMobile = " + p_mobile + " " 
    + OR + " pDate = '" + p_date + "' " + OR + " pName = '" + p_Name + "'"; 

如果pMobile是一個字符串,那麼你將需要改變+ " pMobile = " + p_mobile + " "+ " pMobile = '" + p_mobile + "' "

相關問題