我一般都是用insert命令来做的,当然也可以用replace
假设RCD1表单上有text1,text2,text3控件,在数据表main中对应的字段为aa,bb,cc(都为字符型,如果不是字符型注意格式转化)
在"确定"按钮下如下代码:
lsaa=alltrim(thisform.text1.value)
lsbb=alltrim(thisform.text2.value)
lscc=alltrim(thisform.text3.value)
INSERT into main(aa,bb,cc) values(lsaa,lsbb,lscc)
thisform.text1.value=''
thisform.text2.value=''
thisform.text3.value=''
thisform.refresh
我给一段我的"添加/保存"按钮的完整代码给你,不过我的功能和你的不一样,我是先清空,然后再输入数据,再点"保存",就可以保存数据了.
首先设置这个command的caption为"添加"
command1 click事件中这样写的:
IF this.Caption ='添加'
this.Caption='保存'
fOR i=1 to 3
mytext="text"+ALLTRIM(STR(i))
thisform.&mytext..readonly=.f.&&由于在表单初始化时,使这样控件都是只读的,现在使只读属性为假
endfor
thisform.text1.text1.Value='' &&清空(我的text是一个事先做好的text类,所以每个前面都有text)
thisform.text2.text1.Value=''
thisform.text3.text1.Value=''
thisform.save1.command3.Enabled =.f. &&修改按钮不可用
thisform.save1.command2.Enabled =.f. &&删除按钮不可用
thisform.pointer1.command1.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command2.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command3.Enabled=.f. &&指针按钮不可用
thisform.pointer1.command4.Enabled=.f. &&指针按钮不可用
thisform.text1.text1.setfocus
ELSE
lsname=ALLTRIM(thisform.text1.text1.Value )
lscusname=ALLTRIM(thisform.text2.text1.Value )
lsphone=ALLTRIM(thisform.text3.text1.Value)
IF EMPTY(lsname)
MESSAGEBOX("输入的信息不完整,药店名称不能为空",16,'系统提示')
thisform.text1.text1.setfocus
else
INSERT into drugstore(storename,cusname,phone) values(lsname,lscusname,lsphone)
MESSAGEBOX('数据添加成功',48,'操作成功')
thisform.pointer1.command1.Enabled=.t.
thisform.pointer1.command2.Enabled=.t.
thisform.pointer1.command3.Enabled=.t.
thisform.pointer1.command4.Enabled=.t.
thisform.save1.command2.Enabled =.t.
thisform.save1.command3.Enabled =.t.
endif
this.Caption ='添加'
GO bottom
FOR i=1 to 3
mytext="text"+ALLTRIM(STR(i))
thisform.&mytext..enabled=.f.
endfor
thisform.Refresh
ENDIF
可以先建一个临时表作为表单的数据源,然后在保存命令中用replace替换字段;清空临时表字段,refresh表单.ok