CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  数据库(包含打印,安装,报表)

关于Adodc+Datagrid+Access的问题,实在解决不了了!求助!

楼主yuanchaoj(菜鸟)2003-11-03 16:48:22 在 VB / 数据库(包含打印,安装,报表) 提问

1、我在查询时用   Adodc连接到Access数据库的一张表,想用几个查询条件约束进行组合查询,然后在Datagrid中显示结果,因此将查询条件设为变量,然而实现不了。  
  2、我不用变量,单写where查序号可查,比如我表里有序号为1、2、3、4四条数据,我在序号栏输入1、2、3、4都分别可查到这四条,输入5或6、7、……时我用MSgbox写的“未找到……”即发挥作用弹了出来,可是当我回头输入1、2、3、4时,也弹出来了,竟然开始能查现在也查不了了,这是为什么?各位高手,谢谢了!  
  代码如下:  
  Option   Explicit  
  Dim   cx   As   String  
  Dim   cxt1   As   String,   cxt2   As   String,   cxt3   As   String  
  Dim   cxt4   As   String,   cxt5   As   String,   cxt6   As   String  
   
  Private   Sub   Command1_Click()  
  MsgBox   cx  
  If   cx   =   ""   Then  
  MsgBox   "请输入查询条件!",   vbExclamation,   "错误"  
  Exit   Sub  
  DataGrid1.ClearFields  
  End   If  
  With   Adodc1  
              .CursorLocation   =   adUseClient  
              .CursorType   =   adOpenStatic  
              .CommandType   =   adCmdText  
              .RecordSource   =   "Select   *   from   资料总表   where"   +   cx  
              .Refresh  
        End   With  
  Set   DataGrid1.DataSource   =   Adodc1  
  Adodc1.Refresh  
  cx   =   ""  
  If   Text4   =   ""   Then  
  MsgBox   "没有找到符合条件的记录!",   vbExclamation  
  End   If  
  cx   =   ""  
  End   Sub  
   
   
  Private   Sub   Form_Load()  
  Text1   =   ""  
  Text2   =   ""  
  Text3   =   ""  
  Combo1.Text   =   ""  
  Combo2.Text   =   ""  
  Combo3.Text   =   ""  
  Combo4.Text   =   ""  
  Combo5.Text   =   ""  
  Combo6.Text   =   ""  
  Combo7.Text   =   ""  
  Combo8.Text   =   ""  
  End   Sub  
   
   
  Private   Sub   Text2_Change()  
  cxt2   =   "   标题   like   "   +   "'"   +   Text2   +   "%"   +   "'"  
  If   cx   <>   ""   Then  
  cx   =   cx   +   "   and   "   +   cxt2  
  Else  
  cx   =   cxt2  
  End   If  
  End   Sub  
   
  Private   Sub   Text3_Change()  
  cxt1   =   "   序号="   +   "'"   +   Text3   +   "'"  
  If   cx   <>   ""   Then  
  cx   =   cx   +   "   and"   +   cxt1  
  Else  
  cx   =   cxt1  
  End   If  
  End   Sub  
   
   
  问题点数:0、回复次数:4Top

1 楼yoki(小马哥--鬓微霜,又何妨)回复于 2003-11-03 18:50:15 得分 0

 
  Option   Explicit  
  Dim   cx   As   String  
  Dim   cxt1   As   String,   cxt2   As   String,   cxt3   As   String  
  Dim   cxt4   As   String,   cxt5   As   String,   cxt6   As   String  
   
  Private   Sub   Command1_Click()  
  cx="     where   1=1"  
  cx=iif(trim(text3.text)<>"",cx+   "   and   序号="   +   "'"   +   Text3   +   "'",cx)  
  cx=iif(trim(text2.text)<>"",cx+   "   and   标题   like   "   +   "'"   +   Text2   +   "%"   +   "'",cx)  
  MsgBox   cx  
  If   cx   =   ""   Then  
  MsgBox   "请输入查询条件!",   vbExclamation,   "错误"  
  Exit   Sub  
  DataGrid1.ClearFields  
  End   If  
  With   Adodc1  
              .CursorLocation   =   adUseClient  
              .CursorType   =   adOpenStatic  
              .CommandType   =   adCmdText  
              .RecordSource   =   "Select   *   from   资料总表"   +   cx  
              .Refresh  
        End   With  
  Set   DataGrid1.DataSource   =   Adodc1  
  Adodc1.Refresh  
  cx   =   ""  
  If   Text4   =   ""   Then  
  MsgBox   "没有找到符合条件的记录!",   vbExclamation  
  End   If  
  cx   =   ""  
  End   Sub  
   
   
  Private   Sub   Form_Load()  
  Text1   =   ""  
  Text2   =   ""  
  Text3   =   ""  
  Combo1.Text   =   ""  
  Combo2.Text   =   ""  
  Combo3.Text   =   ""  
  Combo4.Text   =   ""  
  Combo5.Text   =   ""  
  Combo6.Text   =   ""  
  Combo7.Text   =   ""  
  Combo8.Text   =   ""  
  End   Sub  
   
   
   
  Top

2 楼yuanchaoj(菜鸟)回复于 2003-11-05 07:54:53 得分 0

这个方法还是不行,用msgbox   cx一看,查询条件全乱了,小马哥,你还有没有更好的方法啊,小弟在此拜谢了!Top

3 楼li_ping(学习WinFX("Avalon"))回复于 2003-11-05 09:00:27 得分 0

 
  Private   Sub   Command1_Click()  
  cx=""  
  cx=iif(trim(text3.text)<>"",cx+   "序号="   +   "'"   +   Text3   +   "'",cx)  
  cx=iif(trim(text2.text)<>"",cx+   "   and   标题   like   "   +   "'"   +   Text2   +   "%"   +   "'",cx)  
  MsgBox   cx  
  If   cx   =   ""   Then  
  MsgBox   "请输入查询条件!",   vbExclamation,   "错误"  
  Exit   Sub  
  DataGrid1.ClearFields  
  End   If  
  With   Adodc1  
              .CursorLocation   =   adUseClient  
              .CursorType   =   adOpenStatic  
              .CommandType   =   adCmdText  
              .RecordSource   =   "Select   *   from   资料总表"   +   cx  
              .Refresh  
        End   With  
  Set   DataGrid1.DataSource   =   Adodc1  
  Adodc1.Refresh  
  cx   =   ""  
  If   Text4   =   ""   Then  
  MsgBox   "没有找到符合条件的记录!",   vbExclamation  
  End   If  
  cx   =   ""  
  End   Sub  
  Top

4 楼li_ping(学习WinFX("Avalon"))回复于 2003-11-05 09:10:04 得分 0

错了,应该是这样:  
  Private   Sub   Command1_Click()  
  cx=""  
  cxt3=iif(trim(text3.text)<>"","序号="   +   "'"   +   Text3   +   "'","")  
  cxt2=iif(trim(text2.text)<>"","标题   like   "   +   "'"   +   Text2   +   "%"   +   "'","")  
  cx=iif(cxt3<>"",cxt3+"   and   ",cxt3)+cxt2  
  MsgBox   cx  
  If   cx   =   ""   Then  
  MsgBox   "请输入查询条件!",   vbExclamation,   "错误"  
  Exit   Sub  
  DataGrid1.ClearFields  
  End   If  
  With   Adodc1  
              .CursorLocation   =   adUseClient  
              .CursorType   =   adOpenStatic  
              .CommandType   =   adCmdText  
              .RecordSource   =   "Select   *   from   资料总表   where   "   +   cx  
              .Refresh  
        End   With  
  Set   DataGrid1.DataSource   =   Adodc1  
  Adodc1.Refresh  
  cx   =   ""  
  If   Text4   =   ""   Then  
  MsgBox   "没有找到符合条件的记录!",   vbExclamation  
  End   If  
  cx   =   ""  
  End   Sub  
  Top

相关问题

  • adodc与datagrid
  • datagrid连接adodc
  • view+ADODC+DATAGRID?
  • 数据库连接不上,adodc控件+access+datagrid
  • adodc和datagrid的邦定
  • adodc
  • DataGrid 和 ADODC的问题,急需解决!
  • VC++下如何操作Adodc,DataGrid控件???
  • 急用,adodc及datagrid的用法
  • 关于Adodc和DataGrid的问题

关键词

  • 查询
  • cxt
  • adodc
  • cx
  • thenmsgbox
  • combo
  • clearfieldsend
  • ifcx
  • ifwith
  • refreshcx

得分解答快速导航

  • 帖主:yuanchaoj

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo