vfp中的插入问题

来源:百度知道 编辑:UC知道 时间:2024/06/20 07:25:53
我在vfp中建立了一个“插入表单”,功能都可以实现,但是总是显示 主属性 不唯一,是怎么回事。
比如,在学生表中插入一个学生的记录(学号,姓名,性别,班号)
执行完操作后,提示 学号 不唯一。
我的确定按钮里的代码是:
sele student
use student
append blank
thisform.refresh
go bottom
replace 学号 with thisform.pageframe1.page1.学号1.value
replace 姓名 with thisform.pageframe1.page1.姓名1.value
replace 性别 with thisform.pageframe1.page1.性别1.value
replace 民族 with thisform.pageframe1.page1.民族1.value
replace 出生日期 with thisform.pageframe1.page1.出生日期1.value
replace 班号 with thisform.pageframe1.page1.班号1.value
replace 备注 with thisform.pageframe1.page1.备注1.value

你先检查下表里是否有你要插入这个学号的数据
sele student
use student
locate for 学号= thisform.pageframe1.page1.学号1.value
if found()
messagebox("该学号的数据已经存在")
else
append blank
go bottom
replace 学号 with thisform.pageframe1.page1.学号1.value
replace 姓名 with thisform.pageframe1.page1.姓名1.value
replace 性别 with thisform.pageframe1.page1.性别1.value
replace 民族 with thisform.pageframe1.page1.民族1.value
replace 出生日期 with thisform.pageframe1.page1.出生日期1.value
replace 班号 with thisform.pageframe1.page1.班号1.value
replace 备注 with thisform.pageframe1.page1.备注1.value
endif

还有如果是插入新纪录建议用Insert命令

是应该先检查一下输入的【学号】是否存在。

楼上 magic_ycf程序有点问题:
1、如果发现【学号】重复,提示后应该返回,否则还会继续往下执行
2、楼主已经建立索引,loca速度太慢(如果记录多了很要命)
设置了【学号索引后】建议把:
locate for 学号= thisform.pageframe1.page1.学号1.value
if found()
改成:
if seek(thisform.pageframe1.page1.学号1.value)

另外应该:
删除程序里面的go bottom

因为: