帮忙看看Dropdownlist的错误

soislove 2006-05-09 08:56:51
我想用几个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一切正常,请高手帮忙找下原因
...全文
142 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
JESSONXUE 2006-05-10
  • 打赏
  • 举报
回复
你做一个简单的SQL语句输出,判断一下SQL语句是否正确!
soislove 2006-05-09
  • 打赏
  • 举报
回复
与我设计的不一样
我本想DropDownList.SelectedValue的值为空的时候不对相应的数据筛选
但是现在DropDownList.SelectedValue的值为空就加上筛选条件DropDownList.SelectedValue=""
soislove 2006-05-09
  • 打赏
  • 举报
回复
还是不行
空格加了
sql也该了
sql = "select * from kucun where id<>'3'"
sql0=“”也初始化了还不行
webwalker 2006-05-09
  • 打赏
  • 举报
回复
呵呵

vb一样写…… 公用……
SimpleDay 2006-05-09
  • 打赏
  • 举报
回复
程序上没问题,
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
careast 2006-05-09
  • 打赏
  • 举报
回复
是不是sql语句中缺少空格
SimpleDay 2006-05-09
  • 打赏
  • 举报
回复
trim(DropDownLIst3.SelectedValue)
webwait 2006-05-09
  • 打赏
  • 举报
回复
DropDownList3.SelectedValue.Trim()
vb不知道怎么写
webwait 2006-05-09
  • 打赏
  • 举报
回复
Dim sql, sql0 As String
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
soislove 2006-05-09
  • 打赏
  • 举报
回复
还是这个啊:
服务器: 消息 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' 附近有语法错误。
soislove 2006-05-09
  • 打赏
  • 举报
回复
DropDownList1.SelectedValue "泡沫 " String
DropDownList2.SelectedValue " " String
sql "select * from kucun where huowu<>''" String
sql0 Nothing String
是这个么?
soislove 2006-05-09
  • 打赏
  • 举报
回复
见笑,见笑。
何谓输出,怎么弄
码视野 2006-05-09
  • 打赏
  • 举报
回复
把输出的sql语句贴出来看下

If DropDownList2.SelectedValue <> "" Then
sql0 = sql0 & "and xinghao='" & DropDownList2.SelectedValue & "' "
End If
这里注意空格
chenyuming2004 2006-05-09
  • 打赏
  • 举报
回复
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

你运行时把这个SQL输出,拿到查询分析器来看看了.
码视野 2006-05-09
  • 打赏
  • 举报
回复
不正常?有什么提示,怎么样不正常?
humin1906 2006-05-09
  • 打赏
  • 举报
回复
最好是SQL语句到查询分析器里测试一下。就很清楚了
humin1906 2006-05-09
  • 打赏
  • 举报
回复
程序上没问题,
sql = "select * from kucun where huowu<>''"
If DropDownList1.SelectedValue <> "" Then
sql0 = " and huowu='" & DropDownList1.SelectedValue & "'"
End If
这里是不是有问题,
where huowu<>'' 和 and huowu='" & DropDownList1.SelectedValue

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧