标题:求教一条VB 数据库语句
取消只看楼主
ictest
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:325
专家分:114
注 册:2010-2-17
结帖率:69.81%
已结贴  问题点数:20 回复次数:3 
求教一条VB 数据库语句
两个问题
1、想在   Adodc1.RecordSource = "select * from pingjunzhi where   语句后添加如下条件,这条语句怎么写?
日期   between   Text1.Text  和  Text7.Text  之间
品种名  =  Text2.Text
批号    =  Text3.Text
文件名  =  Text4.Text
参数名  =  Text5.Text
Site号  =  Text6.Text

2、什么符号是数据库里的通配符?也就是说文本框内填写什么符号,发出筛选命令后它是显示所有的。
举例说明:
数据库里有一项“批号”列,内有数字“1”、“2”、“3”、“4”、“5”,在筛选文本框内填写数字,DataGrid中“批号”列就显示相应数字的那一行,
现想在筛选文本框内填写一个符号(不知是* 还是%,或者其他符号),“批号”列就显示是数字“1”、“2”、“3”、“4”、“5”的行(也就是所有行)。

搜索更多相关主题的帖子: 数据库 语句 Text 符号 数字 
2017-08-07 00:50
ictest
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:325
专家分:114
注 册:2010-2-17
得分:0 
对不起,我的意思没有表达清楚,我想表达的意思应该是:多条件多种组合查询。
比如数据库的结构是:
日期  、 品种名  、批号   、文件名  、参数名  、Site号 、数值
首先确定的是 日期(between   Text1.Text  和  Text7.Text  之间)是必选条件,
接下来
有可能只筛选满足 日期(between   Text1.Text  和  Text7.Text  之间)的数据,
也可能会筛选满足 品种名(=Text2.Text)、批号 (=Text3.Text)、文件名(=  Text4.Text)、参数名(=  Text5.Text)、Site号(=  Text6.Text)组合条件的数据;
也可能会筛选满足 品种名(=Text2.Text)、参数名(=  Text5.Text)、Site号(=  Text6.Text)组合条件的数据;
也可能会筛选满足 品种名(=Text2.Text)、批号 (=Text3.Text)、Site号(=  Text6.Text)组合条件的数据;
        .
        .
        .
        .
        .
        .
不知道 Adodc1.RecordSource = "select * from pingjunzhi where 语句后如何添加各种筛选条件组合,求教各位大神和版主大大这条语句怎么写?

[此贴子已经被作者于2017-8-7 15:25编辑过]

2017-08-07 15:24
ictest
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:325
专家分:114
注 册:2010-2-17
得分:0 
求教这段语句怎么写?谢谢!
2017-08-07 16:15
ictest
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:325
专家分:114
注 册:2010-2-17
得分:0 
恕我驽钝,我是这样写的:
程序代码:
Dim s1 As String
Dim s2 As String
Dim s3 As String
Dim s4 As String
Dim s5 As String

If Len(Trim(Text2.Text)) > 0 Then         
Text11.Text = " 品种名 = '" & Trim(Text2.Text) & "'"  
Else
Text11.Text = " 1=1 "
End If

If Len(Trim(Text3.Text)) > 0 Then      
Text12.Text = " 批号 = '" & Trim(Text3.Text) & "'"     
Else
Text12.Text = " 2=2 "
End If

If Len(Trim(Text4.Text)) > 0 Then    
Text13.Text = " 文件名 = '" & Trim(Text4.Text) & "'"     
Else
Text13.Text = " 3=3 "
End If

If Len(Trim(Text5.Text)) > 0 Then     
Text14.Text = " 参数名 = '" & Trim(Text5.Text) & "'"   
Else
Text14.Text = " 4=4 "
End If

If Len(Trim(Text6.Text)) > 0 Then     
Text15.Text = " Site号 = '" & Trim(Text6.Text) & "'"     
Else
Text15.Text = " 5=5 "
End If

Adodc1.RecordSource = "Select * From pingjunzhi Where 日期>=#" & CDate(Text1.Text) & "# And 日期<= #" & CDate(Text7.Text) & "# 'and " & (Text11.Text) & " and " & (Text12.Text) & " and " & (Text13.Text) & " and " & (Text14.Text) & " and " & (Text15.Text) & ""
  Adodc1.Refresh
  Set DataGrid1.DataSource = Adodc1


如果只选择两个日期范围,其他的(Text2.Text~Text6.Text)为空,则报如下错误:

如果(Text1.Text~Text7.Text)全有内容,且这些数据在数据库中确实存在,则报如下错误:


实在不知哪里错了,恳求各位教教我!谢谢!
2017-08-08 17:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-479832-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.749067 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved