本地局域网主机安装了SQL数据库。所有需要查询和保存的数据都保存在主机的SQL数据库表中。
现在数据库中有表tb_caohai_zf。里面有若干字段。需要对其中一个字段(日期)进行时间段查询(比如20120101-20120801).字段类型是字符型。
查询表单2个文本控件 TEXT1和TEXT2
下面是我查询按钮CLICK的代码
IF len(alltrim(thisform.text1.value))=0
messagebox("请填入起始的出生日期",16,"系统提示")
thisform.text1.setfocus
else
*if thisform.text2.value={}
IF len(alltrim(thisform.text2.value))=0
messagebox("请填入终止的出生日期",16,"系统提示")
thisform.text2.setfocus
else
strsql = "Select * from tb_caohai_zf where Caohai_id between thisform.text1.value and thisform.text2.value order by Caohai_id desc"
nHandle = GetDataHandle()
IF nHandle <= 0 THEN
MESSAGEBOX("无法连接数据库!", 0+16, "错误")
RETURN .F.
ENDIF
thisform.LockScreen = .t.
thisform.grid1.RecordSource = null
ret = SQLEXEC(nHandle, strsql, "tmp")
= SQLDISCONNECT(nHandle)
IF ret > 0
IF USED("tmp_stud1")
USE IN tmp_stud1
ENDIF
Select 0
Use DBF("tmp") Again Alias tmp_stud1
Use In tmp
WITH thisform.GRID1
.RECORDSOURCE = "tmp_stud1"
.COLUMN1.CONTROLSOURCE = "Caohai_id"
.COLUMN2.CONTROLSOURCE = "Caohai_id"
.COLUMN3.CONTROLSOURCE = "Tranperson"
.COLUMN4.CONTROLSOURCE = "m_m_1"
.COLUMN5.CONTROLSOURCE = "m_m_2"
.COLUMN6.CONTROLSOURCE = "s_m_1"
.COLUMN7.CONTROLSOURCE = "n_m_2"
.REFRESH
ENDWITH
ELSE
MESSAGEBOX("连接数据库时发生错误!", 0+16, "错误")
ENDIF
ENDIF
ENDIF
thisform.LockScreen = .f.
------解决方案--------------------------------------------------------
把这句
strsql = "Select * from tb_caohai_zf where Caohai_id between thisform.text1.value and thisform.text2.value order by Caohai_id desc"
改了先
d1 = thisform.text1.value
d2 = thisform.text2.value
strsql = "Select * from tb_caohai_zf where Caohai_id between ?d1 and ?d2 order by Caohai_id desc"
其他还有什么问题明确写出来