2013-10-01 112 views
-1

如何過濾我的組合框顯示如果我的Label.text ="ad",我想只顯示那些在數據庫上有「ad」不顯示所有。 但錯誤無效參數=值'0'對於SelectedIndex參數名稱無效:Selectedindex「出現」。錯誤無效參數='0'的值對於SelectedIndex參數名稱無效:Selectedindex

Private Sub FillCombo() 
    Try 
     conn = New OleDbConnection(Get_Constring) 

     Dim sSQL As String = ("SELECT subject FROM student where subject like'" & Label25.Text & "%' ") 
     Dim da As New OleDbDataAdapter(sSQL, conn) 

     Dim ds As New DataSet 
     da.Fill(ds) 

     cmbsection.ValueMember = "subject" 
     cmbsection.DataSource = ds.Tables(0) 
     cmbsection.SelectedIndex = 0 

    Catch ex As Exception 
     MsgBox("ERROR : " & ex.Message.ToString) 
    End Try 
End Sub 
+2

你確定你的查詢實際上返回的結果嗎?如果cmbsection控件有0個項目,則不能將您的SelectedIndex設置爲第一個項目。 – JDB

+0

這應該是什麼適當的代碼。 – user2715202

+0

我還會補充說你的應用程序有一個教科書[SQL注入攻擊](http://msdn.microsoft.com/en-us/library/ff648339.aspx)漏洞。 – JDB

回答

0
Dim sSQL As String = ("SELECT subject FROM student where **username** like'" & Label25.Text & "%' ") 

solved :)