2012-06-13 34 views
0

我不知道該怎麼做:SqlQuery類(聲明,則params)

params= new object[]{ new SqlParameter("ID",val),new SqlParameter("Label","'%Name%'")}; 
statement = "Select ID, Label from Country Where ID = ? or or Label Like ?"; 

我想它給了我: '?'

附近有語法錯誤。

+0

通常,使用ADO.NET(其中EF被窩裏用)時,您需要使用'@ID '或'@ Label'參數佔位符在SQL查詢中 - 不僅僅是'''作爲參數的佔位符。所以試試:'SELECT ID,Label FROM dbo.Country WHERE ID = @ID或Label LIKE @ Label'作爲你的SQL語句 –

回答

2

你有一個錯字:

"Select ID, Label from Country Where ID = ? or or Label Like ?"; 

應該

"Select ID, Label from Country Where ID = ? or Label Like ?";