FoxPro 表单不更新表格
我创建了一个非常简单的表单,其中包含两个文本框和一个“更新位置”按钮,其输入的值应该更新到数据库中的两个链接表。我最终尝试将其放入独立的应用程序中,但现在我只希望表单本身能够工作。我对 FoxPro 非常陌生,所以我不知道是否可以只用一个表单来更新我的表格,或者工作中是否存在其他问题。
这是我的“更新位置”按钮的代码(OldLoc 是第一个文本框,NewLoc 第二个文本框):
SET DATABASE TO LOCATIONS
CLOSE ALL DATABASES
OPEN DATABASE locations\locations EXCLUSIVE
IF this.parent.OldLoc.Value == "" then
MESSAGEBOX('Please fill in the old location.', 48, 'Missing Location Information')
this.parent.OldLoc.SetFocus
ELSE
INDEX ON table1.loc TAG loc
SET ORDER TO loc
SEEK this.parent.OldLoc.Value IN table1
IF FOUND()
IF this.parent.NewLoc.Value == "" then
MESSAGEBOX('Please fill in the new location.', 48,
'Missing Location Information') this.parent.NewLoc.SetFocus
UPDATE table1 SET loc = this.parent.NewLoc.Value ;
WHERE loc = this.parent.OldLoc.value
UPDATE table2 SET loc = this.parent.NewLoc.Value ;
WHERE loc = this.parent.OldLoc.value
ENDIF
ENDIF
ENDIF
感谢您的任何输入!
I've created a very simple form with two textboxes and an 'update locations' button, the inputted values of which should be updating to two linked tables in a database. I'm eventually trying to put this in a standalone application but for now I just want the form itself to work. I'm very new to FoxPro so I don't know if it's possible for just a form to update my tables, or if there's some other issue at work.
Here's the code for my 'update locations' button (OldLoc is the first textbox and NewLoc the second):
SET DATABASE TO LOCATIONS
CLOSE ALL DATABASES
OPEN DATABASE locations\locations EXCLUSIVE
IF this.parent.OldLoc.Value == "" then
MESSAGEBOX('Please fill in the old location.', 48, 'Missing Location Information')
this.parent.OldLoc.SetFocus
ELSE
INDEX ON table1.loc TAG loc
SET ORDER TO loc
SEEK this.parent.OldLoc.Value IN table1
IF FOUND()
IF this.parent.NewLoc.Value == "" then
MESSAGEBOX('Please fill in the new location.', 48,
'Missing Location Information') this.parent.NewLoc.SetFocus
UPDATE table1 SET loc = this.parent.NewLoc.Value ;
WHERE loc = this.parent.OldLoc.value
UPDATE table2 SET loc = this.parent.NewLoc.Value ;
WHERE loc = this.parent.OldLoc.value
ENDIF
ENDIF
ENDIF
Any input you have is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在点击事件中做了多余的工作...关闭数据库,然后重新打开,然后打开独占。您尝试更新的表应该已经在您计划连接或搜索的关键列上有一个索引。完成后,您不需要一遍又一遍地显式创建索引标签...创建索引“TAG”后,您不需要再次执行...
因此,话虽这么说...
打开窗体,并打开“INIT”事件。在那里,您可以在使用表单时显式打开要使用的表...
现在,更新按钮的“CLICK”事件...预先验证是否有值,不用担心尝试寻找或更新,除非两者都已填写...
you are doing redundant work in your click event... Closing the database, then re-opening, then opening exclusive. The tables you are trying to update, should already have an index on the key columns you ever plan to join or search based on. Once that is done, you don't need to explicitly create the index tag over and over... Once an index "TAG" is created, you don't need to do again..
So, that being said...
Open the form, and open the "INIT" event. In there, that is where you can explicitly open the tables for use while the form is in use...
Now, the "CLICK" event of your update button... Pre-validate that there are values, don't worry about trying to seek or update unless BOTH are filled in...
您可能还想查看表单的数据环境。
您可以选择表单加载时要打开的表,这样可以在表单加载事件或表单初始化事件中显式打开它们,
我对“更新位置”按钮的单击事件的简陋提供是:-
这应该是唯一需要的代码。显然,可以对上述内容进行许多改进,但本质上就可以完成这项工作。
如果您想查看从头开始构建的上述表单,请发送一封电子邮件至 [email protected ]我会给你一个直播示范。
You might also want to take a look at the data environment of the form.
You can select which tables the form is to open when the form loads, this saves explicitly opening them either in the forms load event or in the forms init event
My humble offering for the Click Event of the 'Update Locations' button is :-
This should be the only code required. Clearly there are many improvements that can be made to the above , but in essence that will do the job.
If you would like to see the above form built from scratch, pop an email to [email protected] and I will give you a live demonstration.