我想用几个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一切正常,请高手帮忙找下原因
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一切正常,请高手帮忙找下原因
解决方案 »
- Repeater绑定显示字段
- 在XP IIS5下运行正常,为什么到win2003 IIS6下,下拉列表(DropdownList)的下拉回传会失效啊?
- 关于某人询问的.net内部对象的回答
- Linq To Sql菜鸟级问题,有时间的就进来帮忙看下~~
- CSDN发贴时的登录效果怎么做的?
- 为什么dataset不能插入~~~~~
- 哪位大侠帮帮忙,怎么编写日志管理和用户监控模块啊!!!!1急救!!!!!11
- 各位老大,能不能全面介绍一下.net里的正则表达式?(up有分)在线
- 这种情况怎么将*.vb编译成dll文件?
- 动态设置控件?
- datagrid里面的CheckBox的异常!!
- ASP.NET 不换行的问题
sql = "select * from kucun where huowu<>''"
If DropDownList1.SelectedValue <> "" Then
sql0 = " and huowu='" & DropDownList1.SelectedValue & "'"
End If
这里是不是有问题,
where huowu<>'' 和 and huowu='" & DropDownList1.SelectedValue
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你运行时把这个SQL输出,拿到查询分析器来看看了.
sql0 = sql0 & "and xinghao='" & DropDownList2.SelectedValue & "' "
End If
这里注意空格
DropDownList2.SelectedValue " " String
sql "select * from kucun where huowu<>''" String
sql0 Nothing String
是这个么?
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: '=' 附近有语法错误。
服务器: 消息 1038,级别 15,状态 1,行 2
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 156,级别 15,状态 1,行 2
在关键字 'Then' 附近有语法错误。
服务器: 消息 1038,级别 15,状态 1,行 5
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 156,级别 15,状态 1,行 5
在关键字 'Then' 附近有语法错误。
服务器: 消息 1038,级别 15,状态 1,行 8
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 156,级别 15,状态 1,行 8
在关键字 'Then' 附近有语法错误。
服务器: 消息 1038,级别 15,状态 1,行 11
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 156,级别 15,状态 1,行 11
在关键字 'Then' 附近有语法错误。
服务器: 消息 10
38,级别 15,状态 1,行 14
不能使用空白的对象或列名。如果必要,请使用一个空格。
服务器: 消息 156,级别 15,状态 1,行 14
在关键字 'Then' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,行 17
第 17 行: 'sql0' 附近有语法错误。
sql0=""
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
vb不知道怎么写
sql = "select * from kucun where huowu<>''"
If DropDownList1.SelectedValue <> "" Then
sql0 = " and huowu='" & DropDownList1.SelectedValue & "'"
End If
这里是不是有问题,
where huowu<>'' 和 and huowu='" & DropDownList1.SelectedValue同是huowu 就 用 or 别用 and
空格加了
sql也该了
sql = "select * from kucun where id<>'3'"
sql0=“”也初始化了还不行
我本想DropDownList.SelectedValue的值为空的时候不对相应的数据筛选
但是现在DropDownList.SelectedValue的值为空就加上筛选条件DropDownList.SelectedValue=""