2014-02-06 5 views
1

내가 코드SQLite는 쿼리

premios pre = new premios() { name = "premio1", link = "http://www.host.com/image.png" }; 
       if (DB.CheckPremios(pre)) 
{//does stuff 
} 

이 조각을 가지고 있고 CheckPremios 기능이 하나입니다 :

public bool CheckPremios(premios pre) 
     { 
      using (var db = new SQLiteConnection(dbPath)) 
      { 
       var existing = db.Query<premios>("select * from premios where name =" + pre.name); 
       if (existing != null) 
       { 
        return true; 
       } 
      } 
      return false; 
     } 

추가 정보 : 이러한 열 : premio1

열 "Premio1"이 존재하지 않는다고 불평하고, "Premio1"도 열 이름을 포함하지 않는다고 불평합니다 ...

내 검색어가 잘못 되었나요?

답변

0

쿼리 호출이 잘못되었습니다. 주로 쿼리 값을 따옴표로 묶지 않았기 때문에 SQLite는 열 값과 비교하여 쿼리 값을 처리합니다. 작은 따옴표를 추가하는 대신 대체 호출을 사용하여 매개 변수 목록을 전달할 위치를 지정하고 다음과 같이 매개 변수 목록을 전달하는 것이 좋습니다.

var existing = db.Query<premios>("select * from premios where name = ?", pre.name); 
if (existing != null) 
{ 
    return true; 
}