PowerBuilder:使用数据窗口插入数据

发布于 2024-09-06 00:10:16 字数 249 浏览 2 评论 0原文

假设我有一个名为“test”的表,其中包含名为 test_idtest_nametest_age 的三列。我使用了一个名为 :al_test_id 的检索参数来提示用户插入 ID 并在数据库中搜索相应的 ID 条目,如果找到,则将其显示给用户。现在,如果没有找到条目,那么我希望用户能够使用他/她作为检索参数输入的 id 插入新行。

我怎样才能做到这一点?

Suppose I have a table called 'test', into which there are three columns named test_id, test_name and test_age. I have used a retrieval argument called :al_test_id to prompt the user to insert an id and search the database for the corresponding id entries, and if found, display it to the user. Now if no entry is found, then I want the user to be able to insert a new row using the id that he/she entered as the retrieval argument.

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

归属感 2024-09-13 00:10:16

所以,这个问题有很多解决方案。这是一个。

在用户启动搜索时触发的事件中(注意 ii_TestID 是一个实例变量,其他变量声明是本地的,留给您):

ii_TestID = Integer (sle_SearchTest.Text)
ll_RowCount = dw_Test.Retrieve (ii_TestID)
IF ll_RowCount = 0 THEN dw_Test.InsertRow(0)

我假设 UI 中没有按钮来添加新的测试结果,所以我们'一次只处理一个。如果要保存:

li_ID = dw_Test.GetItemNumber (1, "test_id")
IF IsNull (li_ID) OR li_ID = 0 THEN dw_Test.SetItem (1, "test_id", ii_TestID)
dw_Test.Update()

为什么我要等到最后一刻才设置 test_id?因此,我可以在窗口的 CloseQuery 事件中编写类似的代码:

IF dw_Test.ModifiedCount() > 0 or dw_Test.DeletedCount() > 0 THEN
   CHOOSE CASE MessageBox ("Huh?", "Would you like to save your changes before exiting?", Question!, YesNoCancel!)
      CASE 1
         EVENT ue_Save()
      CASE 2
         // do nothing
      CASE 3
         RETURN 1
   END CHOOSE
END IF

如果我在 InsertRow() 之后立即更改了 test_id,则 ModifiedCount() 会立即将该行注册为更改,即使用户没有执行任何操作然而。没有什么比在我还没有进行任何更改时计算机提示我保存更改更烦人的了。

祝你好运,

特里。

So, there are many solutions to this problem. Here's one.

In an event fired when the user initiates a search (note ii_TestID is an instance variable, other variable declaration local and left to you):

ii_TestID = Integer (sle_SearchTest.Text)
ll_RowCount = dw_Test.Retrieve (ii_TestID)
IF ll_RowCount = 0 THEN dw_Test.InsertRow(0)

I'm going to assume there's no button in the UI to add a new test result, so we'll be dealing with just one at a time. In the event to save:

li_ID = dw_Test.GetItemNumber (1, "test_id")
IF IsNull (li_ID) OR li_ID = 0 THEN dw_Test.SetItem (1, "test_id", ii_TestID)
dw_Test.Update()

Why am I leaving setting the test_id until the last minute? So I can code something like this in the CloseQuery event of the window:

IF dw_Test.ModifiedCount() > 0 or dw_Test.DeletedCount() > 0 THEN
   CHOOSE CASE MessageBox ("Huh?", "Would you like to save your changes before exiting?", Question!, YesNoCancel!)
      CASE 1
         EVENT ue_Save()
      CASE 2
         // do nothing
      CASE 3
         RETURN 1
   END CHOOSE
END IF

If I had changed the test_id right after InsertRow(), then ModifiedCount() would have registered the row as changed right away, even though the user hadn't done anything yet. Nothing more annoying than having a computer prompt me to save my changes when I haven't made any.

Good luck,

Terry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文