窗体中有文本、下拉列表框、表格控件,grid控件的recordsourcetype属性=1
recordsoruce属性=生成的临时表名称
我想在表单中实现用户通过在文本框中输入内容和选择下拉列表框来
组合查询条件,然后用SQL语句生成临时表在grid控件中显示,具体代码如下。
pcqkemu=alltrim(thisform.combo2.listitem(thisform.combo2.listitemid))
pcqhkbz=pclisthkbz(thisform.combo3.listindex)
pcqaddresswt=alltrim(thisform.text1.text)
pcqyhname=alltrim(thisform.text2.text)
pcqdkdate=ctod(alltrim(thisform.text3.text))
pcqdkjine=val(alltrim(thisform.text4.text))
pcqdkenddate=val(alltrim(thisform.text5.text))
pcqkemu1=iif(empty(pcqkemu),"","kemu=pcqkemu")
if empty(pcqkemu1)
pcqaddresswt1=iif(empty(pcqaddresswt),""," addresswt=pcqaddresswt")
else
pcqaddresswt1=iif(empty(pcqaddresswt),""," and addresswt=pcqaddresswt")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1)
pcqyhname1=iif(empty(pcqyhname),""," yhname=pcqyhname")
else
pcqyhname1=iif(empty(pcqyhname),""," and yhname=pcqyhname")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1)
pcqdkdate1=iif(empty(pcqdkdate),""," dkdate=pcqdkdate")
else
pcqdkdate1=iif(empty(pcqdkdate),""," and dkdate=pcqdkdate")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1) and empty(pcqdkdate1)
pcqdkjine1=iif(empty(pcqdkjine),""," dkjine=pcqdkjine")
else
pcqdkjine1=iif(empty(pcqdkjine),""," and dkjine=pcqdkjine")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1) and empty(pcqdkdate1) and empty(pcqdkjine1)
pcqdkenddate1=iif(empty(pcqdkenddate),""," dkenddate=pcqdkenddate")
else
pcqdkenddate1=iif(empty(pcqdkenddate),""," and dkenddate=pcqdkenddate")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1) and empty(pcqdkdate1) and empty(pcqdkjine1) and empty(pcqdkenddate1)
pcqhkbz1=iif(isnull(pcqhkbz),""," hdbz=pcqhkbz")
else
pcqhkbz1=iif(isnull(pcqhkbz),""," and hdbz=pcqhkbz")
endif
if empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1) and empty(pcqdkdate1) and empty(pcqdkjine1) and empty(pcqdkenddate1) and empty(pcqhkbz1)
select * from &pcqsheming order by kemu,addresswt,yhname into cursor temptable
else
select * from &pcqsheming where &pcqkemu1 &pcqaddresswt1 &pcqyhname1 &pcqdkdate1 &pcqdkjine1 &pcqdkenddate1 &pcqhkbz1 order by kemu,addresswt,yhname into cursor temptable
endif
thisform.grid1.recordsourcetype=1
thisform.grid1.recordsource=temptable.dbf
thisform.grid1.refresh

解决方案 »

  1.   

    错误:
    thisform.grid1.recordsource=temptable.dbf
       ==> thisform.grid1.recordsource='temptable'原因:
    a. thisform.grid1.recordsource是字符型。你的等号右边是什么类型?b. 概念问题。select * from ... into cursor temptable
       这个temptable是一个临时产生的表的别名,并不是一个实际的表temptable.dbf,这个临时产生的表会在你关闭时自动被删除。基于此,你需要在 select ... into cursor temptable 前先如下:
       
       select temptable
       usec. 要加上 thisform.grid1.columncount = -1------------------
    如果你的程序没有别的错误,后段应该如此:......
    ......
    else
    pcqhkbz1=iif(isnull(pcqhkbz),""," and hdbz=pcqhkbz")
    endifselect temptable
    useif empty(pcqkemu1) and empty(pcqaddresswt1) and empty(pcqyhname1) and empty(pcqdkdate1) and empty(pcqdkjine1) and empty(pcqdkenddate1) and empty(pcqhkbz1)
       select * from &pcqsheming order by kemu,addresswt,yhname into cursor temptable
    else
       select * from &pcqsheming where &pcqkemu1 &pcqaddresswt1 &pcqyhname1 &pcqdkdate1 &pcqdkjine1 &pcqdkenddate1 &pcqhkbz1 order by kemu,addresswt,yhname into cursor temptable
    endifthisform.grid1.columncount = -1
    thisform.grid1.recordsourcetype=1
    thisform.grid1.recordsource='temptable'
     
    return