2013-10-01 108 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 :)