2015-09-27 61 views
0

這是我的2個參數的查詢。有人可以幫幫我嗎?兩個表之間的查詢

sql = "select * 
     from studentlist 
     where firstname like '%" 
    & Transaction.SEARCHSTUDENT.Text 
    & "%' or studentnum like '%" 
    & Transaction.SEARCHSTUDENT.Text 
    & "%' and not in (select studentnum from borrowing of books where status ='borrowed')" 
+0

請詳細說明。你面臨的問題或錯誤是什麼?你需要什麼幫助? – navigator

+0

Querry錯誤。我希望從學生名單(表格)中獲得不是借書的表格。 –

+1

通過連接字符串來創建查詢只是乞求像這樣的錯誤和SQL注入攻擊。而不是連接,使用例如@name參數('WHERE FirstName LIKE @name ...')的參數化查詢並傳遞該模式作爲參數值。 –

回答

0

如果borrowing of books是你的表名(含空格),它應該與反引號,像這樣被封閉:

`borrowing of books` 

編輯:此外,它看起來像studentnum您的where子句中丟失,所以它應該看起來像這樣:

sql = "select * 
    from studentlist 
    where (firstname like '%" 
& Transaction.SEARCHSTUDENT.Text 
& "%' or studentnum like '%" 
& Transaction.SEARCHSTUDENT.Text 
& "%') and studentnum not in (select studentnum from `borrowing of books` where status ='borrowed')"