我最近在用vb做数据库这一块,由于我是自学,很多地方不大明白,问题是这样的:
在一个窗体上放置了三个标签,三个文本框,一个adodc控件,一个datagrid控件,两个命令按扭,现有一个access数据库,一张"客户信息汇总表"表中有四个字段分别是姓名,性别,年龄,会员编号.三个标签的caption分别为"按姓名查找"."按性别查找"."按会员编号查找".
要求实现的功能是:
当单击命令按扭时datagrid控件显示按要求所找到的所有记录.
例如 当文本框1输入"张三" ,其他两个文本框为空时
     单击命令按扭,这时datagrid控件显示张三在数据库表中的所有相关数据.    或者 当文本框2输入"女", 其他两个文本框为空时
     单击命令按扭,这时datagrid控件显示性别为女的人在数据库表中的所有相关数据.    或者当文本框3输入"0001", 其他两个文本框为空时
     单击命令按扭,这时datagrid控件显示会员编号等于0001的人在数据库表中的所有相关数据.
    渴望给出详细代码
谢谢!
急求!!!!

解决方案 »

  1.   

    用ADO provider连接吧.
    这样就可以自由写查询语句:
    "select * from khxxb where xm=" & text1.text
    "select * from khxxb where xb=" & text2.text
    "select * from khxxb where bh=" & text3.text
      

  2.   

    建议用多条件查DIM sSQL As String
    sSQL = "select * from table where"
    If text1<>"" sSQL= sSQL & " cond1='" & text1.text & "' and"
    if text2<>"" sSQL = sSQL & " cond2='" & text2.text & "' and"
    ......
    '判断结束
    if right(sSQL,3)= "and" then sSQL=left(sSQL,len(sSQL)-3)
    if right(sSQL,5) = "where"  then .... 去掉where 
      

  3.   

    一个思路:dim tmpWhere1 as string
    dim tmpWhere2 as string
    dim tmpWhere3 as string
    dim strSql    as string'条件1
    if trim(text1.text)="" then
        tmpWhere1=""
    else
        tmpWhere1=" and 字段1='"& trim(text1.text) &"'"
    end if
    '条件2
    if trim(text2.text)="" then
        tmpWhere2=""
    else
        tmpWhere2=" and 字段2='"& trim(text2.text) &"'"
    end if
    '条件3
    if trim(text3.text)="" then
        tmpWhere3=""
    else
        tmpWhere3=" and 字段3='"& trim(text3.text) &"'"
    end if'构造SQL查询语句
    strSql=" select * from tablename where 1=1 " & tmpWhere1 & tmpWhere2 & tmpWhere3