vb+sql server中的sql查询语句如何写?(比上一个复杂,很具有挑战性 很急!) 是啊,是一个动态的sql查询,如何写呢?欢迎来讨论 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先添加一个text名为txtsql,将你的查询信息显示在内,cbofield对应问题内容cbooperator对应包含,txtvalue对应abcIf form.cbooperator.Text = "包含" Then form.txtsql.Text = .txtsql.Text + form.cbofield.Text + " like '*" + form.txtvalue.Text + "*'" Else form .txtsql.Text = form.txtsql.Text + form.cbofield.Text + form.cbooperator.Text + "'" + form.txtvalue.Text + "'" End If 你之前的贴子已经给了你方法了,和你现在的这个是一个意思的Private Sub cmdB_Query_Click()Dim SQL As StringDim Qu As New CollectionDim opera As New CollectionIf Qu.Count = 0 Then Qu.Add "rylx" Qu.Add "rybh" Qu.Add "rymc" Qu.Add "xzmc" Qu.Add "zy" ‘以上是你表中的要查询的列名 opera.Add "='" opera.Add "<>'" opera.Add "> '" opera.Add ">='" opera.Add "<='" opera.Add "<='" opera.Add " like '%" opera.Add " not like '%"End IfSQL = "select rybh,rymc,password,rylx,xzmc,zy from ry where "SQL = SQL & Qu(cobQuery_dx(0).ListIndex + 1)SQL = SQL & opera(cobQuery_ys(0).ListIndex + 1)SQL = SQL & txtQuery(0).TextIf cobQuery_ys(0).ListIndex = 6 Or cobQuery_ys(0).ListIndex = 7 Then SQL = SQL & "%"SQL = SQL & "'"If Check1.Value = 1 Then SQL = SQL & " and " SQL = SQL & Qu(cobQuery_dx(1).ListIndex + 1) SQL = SQL & opera(cobQuery_ys(1).ListIndex + 1) SQL = SQL & txtQuery(1).Text If cobQuery_ys(1).ListIndex = 6 Or cobQuery_ys(1).ListIndex = 7 Then SQL = SQL & "%" SQL = SQL & "'"End If此外,这个程序可以用又条件查询!就是那个check1.value来决定! 这个应该是一个动态sql,表是确定了,里面的条件没有确定,不过根据你列出的条件只有一条,所以sql很好写。combo1是需要判定的字段,combo2是选择相应的谓词。combo3是具体值。strsql="select * from tablename where " & combo1.list(combol1.listindex) & combo2.list(combo2.listindex) & combo3.list(combol3.listindex)combo2的写法就看你自己怎么写了,写的简单,操作也简单。 用SELECT CASE语句,对COMBO1,COMBO2的TEXT编程,从而修改sql语句 如果combo2写成不是中文,而是我们sql中的操作,比如= > <,岂不是连case都不用了 :P MSHFlexGrid如何读入ACCESS数据库中的数据 执行十六进制数据(VB) VBS in QTP 菜鸟问题,怎么给文字加上超连接 这样的字符串如何截取和运算?? 我用了别人的控件,应该怎么设置,才可以在别人的机子上正常使用? 关于WIN32API函数OpenDriver的问题 FORTRAN 创建的dll,VB引用的问题 如何在库中的一个字段里查找是否存在某个字符? 如何把一个应用程序和数据库文件帮定发布 有哪位可以帮我描述一下VBA是什么东东吗? 问题,急,很简单,白挣分的,对VB基础过硬者进入。
cbooperator对应包含,txtvalue对应abcIf form.cbooperator.Text = "包含" Then
form.txtsql.Text = .txtsql.Text + form.cbofield.Text + " like '*" + form.txtvalue.Text + "*'"
Else
form .txtsql.Text = form.txtsql.Text + form.cbofield.Text + form.cbooperator.Text + "'" + form.txtvalue.Text + "'"
End If
Dim SQL As String
Dim Qu As New Collection
Dim opera As New CollectionIf Qu.Count = 0 Then
Qu.Add "rylx"
Qu.Add "rybh"
Qu.Add "rymc"
Qu.Add "xzmc"
Qu.Add "zy"
‘以上是你表中的要查询的列名
opera.Add "='"
opera.Add "<>'"
opera.Add "> '"
opera.Add ">='"
opera.Add "<='"
opera.Add "<='"
opera.Add " like '%"
opera.Add " not like '%"
End IfSQL = "select rybh,rymc,password,rylx,xzmc,zy from ry where "
SQL = SQL & Qu(cobQuery_dx(0).ListIndex + 1)
SQL = SQL & opera(cobQuery_ys(0).ListIndex + 1)
SQL = SQL & txtQuery(0).Text
If cobQuery_ys(0).ListIndex = 6 Or cobQuery_ys(0).ListIndex = 7 Then SQL = SQL & "%"
SQL = SQL & "'"If Check1.Value = 1 Then
SQL = SQL & " and "
SQL = SQL & Qu(cobQuery_dx(1).ListIndex + 1)
SQL = SQL & opera(cobQuery_ys(1).ListIndex + 1)
SQL = SQL & txtQuery(1).Text
If cobQuery_ys(1).ListIndex = 6 Or cobQuery_ys(1).ListIndex = 7 Then SQL = SQL & "%"
SQL = SQL & "'"
End If
此外,这个程序可以用又条件查询!就是那个check1.value来决定!
strsql="select * from tablename where " & combo1.list(combol1.listindex) & combo2.list(combo2.listindex) & combo3.list(combol3.listindex)combo2的写法就看你自己怎么写了,写的简单,操作也简单。