在敲组合查询的时候,我遇到了很多问题,比如说查询的语法怎么连接啊,怎么让控件中的文本信息也就是说字段名,组合关系对应数据库表中的字段哪? 也就是说我们要让卡号=cardno,让姓名=studentname ,这样我们在查询的时候才方便了,反成不能直接给combox的
        		在敲组合查询的时候,我遇到了很多问题,比如说查询的语法怎么连接啊,怎么让控件中的文本信息也就是说字段名,组合关系对应数据库表中的字段哪?
也就是说我们要让卡号=cardno,让姓名=studentname ,这样我们在查询的时候才方便了,反成不能直接给combox的text里面上英文的吧? 于是就定义个函数,让它实现这个功能,函数如下。
public function field(i as string) as string    select case i        case 卡号    field = cardno        case 姓名    field = studentname        case 上机日期    field = ondate        case 上机时间    field = ontime        case 下机日期       .......    end selectend function
这样就行了。下面这组合查语法以及代码private sub cmdinqurie_click()    dim ctrl as control    dim mrc as adodb.recordset    dim txtsql as string    dim msgtext as string     '检查条件输入    if trim(cmbfeild1.text) =  or trim(cmboperator1.text) =  or trim(txt1.text) =  then        msgbox 请输入完整的查询条件, , 提示        exit sub    end if        dim i, icols as integer '让所有列都居中显示文字    icols = msflexgrid1.cols    for i = 0 to icols - 1        msflexgrid1.colalignment(i) = flexaligncentercenter    next        txtsql = select * from line_info where     txtsql = txtsql & trim(field(cmbfeild1.text)) & trim((cmboperator1.text)) & ' & trim(txt1.text) & '    if trim(cmbrelation1.text  ) then '第一个组合关系存在        if trim(cmbfeild2.text) =  or trim(cmboperator2.text = ) or trim(txt2.text = ) then            msgbox 你已经选择了第一个组合关系,请输入第二行查询条件, , 提示            exit sub        else            txtsql = txtsql & field(trim(cmbrelation1.text)) &   & field(cmbfeild2.text) & cmboperator2.text & ' & trim(txt2.text) & '        end if    end if        if trim(cmbrelation2.text  ) then '第二个组合关系存在        if trim(cmbfeild3.text) =  or trim(cmboperator3.text) =  or trim(txt3.text) =  then            msgbox 你已经选择了第二个组合关系,请输入第三行查询条件, , 提示            exit sub        else            txtsql = txtsql & field(cmbrelation2.text) &   & field(cmbfeild3.text) & cmboperator3.text & ' & trim(txt3.text) & '        end if    end if    on error goto error1 '错误语句保护,当用户输入查询的格式不对时给出提示信息。    set mrc = executesql(txtsql, msgtext)    if mrc.eof = true then '检查信息是否存在,如果不存在给出提示并清空所有文本框        msgbox 没有查询到结果,可能会你输入的信息不存在,或者信息矛盾        for each ctrl in me.controls        if typeof ctrl is textbox then   '是否为文本框textbox            ctrl.text =                '清空所有文本框        end if        next           for each ctrl in me.controls        if typeof ctrl is combobox then   '是否为文本框textbox            ctrl.text =         end if      next        exit sub    end if    with msflexgrid1        .rows = 1        .textmatrix(0, 0) = 卡号        .textmatrix(0, 1) = 姓名        .textmatrix(0, 2) = 上机日期        ........             do while not mrc.eof            .rows = .rows + 1            .textmatrix(.rows - 1, 0) = trim(mrc!cardno)            .textmatrix(.rows - 1, 1) = mrc!studentname            .textmatrix(.rows - 1, 2) = mrc!ondate            .textmatrix(.rows - 1, 3) = mrc!ontime            ........            mrc.movenext        loop    end with    mrc.closeerror1:    msgbox 你输入的查询信息格式有误,请按标准格式输入。end sub
代码一大堆,这里面最终的的思想是怎样突破我们的固有思维,怎样创新,让我们的思想灌输进来。我们要用到以前所学的知识,达到学以致用的效果,其实还有比这些写更简便实用的代码等待我们开发,钻研。
   
 
   