帮忙看看Dropdownlist的错误
我想用几个dropdownlist实现对数据库的查询,程序如下:
Dim sql, sql0 As String
sql = "select * from kucun where huowu<>''"
If DropDownList1.SelectedValue <> "" Then
sql0 = " and huowu='" & DropDownList1.SelectedValue & "'"
End If
If DropDownList2.SelectedValue <> "" Then
sql0 = sql0 & "and xinghao='" & DropDownList2.SelectedValue & "' "
End If
if DropDownList3.SelectedValue <> "" Then
sql0 = sql0 & " and gongyingshang='" & DropDownList3.SelectedValue & "' "
End If
sql = sql & sql0
Dim sqlcon As New SqlConnection("server=i;uid=sa;pwd=as;database=sheji")
sqlcon.Open()
Dim ds As New DataSet
Dim sqld As New SqlDataAdapter
sqld.SelectCommand = New SqlCommand(sql, sqlcon)
sqld.Fill(ds, "sql")
datagrid.DataSource = ds.Tables("sql")
datagrid.DataBind()
sqlcon.Close()
sqlcon = Nothing
这里是用了3个dropdownlist,对dropdownlist所绑定的数据进行筛选后用button触发事件,
但是这样查询不出数据来,只用1个dropdownlist一切正常,请高手帮忙找下原因