WebRAD:构建基于Web的数据库应用程序
立即解锁
发布时间: 2025-08-22 01:31:36 阅读量: 2 订阅数: 7 


WebRAD:使用Visual FoxPro构建Web数据库应用
# WebRAD:构建基于 Web 的数据库应用程序
## 1. 显示查询结果网格
在 Web 应用程序中,我们常常需要将数据库查询结果以网格形式展示给用户。以下是一个示例代码,展示了如何格式化列标题数组并显示查询结果:
```foxpro
* Write a grid that shows the result
* Format an array to hold the column headings
* (ShowCursor will use the field names as column
* headings if you don't)
aHeaders[1] = "Resource"
aHeaders[2] = "Company"
aHeaders[3] = "Address"
aHeaders[4] = ""
aHeaders[5] = ""
aHeaders[6] = "City"
aHeaders[7] = "State"
aHeaders[8] = "Zip"
* Define a string to use as the page title
lcTitle = "Results for " + m.lcSearchForWhat
.ShowCursor(aHeaders, lcTitle,,,)
* Button for bottom
.WriteLn([<form method="POST" name="form1" id="form1" ;
action="/wr04/wc.dll?wr04process~GetParms">])
.WriteLn([<p><center><input type="submit" name="btnSubmit" value="Done">])
endif
.HTMLFooter()
endwith
ENDFUNC
```
在这段代码中,我们首先定义了一个数组 `aHeaders` 来存储列标题,然后使用 `ShowCursor` 函数显示查询结果。`ShowCursor` 函数使用当前选定的别名,因此我们需要将查询结果发送到一个游标而不是数组。
## 2. 数据库更新操作
除了从数据库中获取数据,我们还需要允许用户向数据库中插入、编辑和删除数据。以下是具体的操作步骤:
### 2.1 添加记录
1. 使用 `request.form` 函数获取用户在表单控件中输入的数据。
2. 使用 `APPEND BLANK` 或 `INSERT INTO` 命令向表中添加一条新记录。
3. 将从网页中获取的值插入到新记录中。
### 2.2 编辑记录
1. 要求用户输入一个值,用于在表中定位匹配的记录。
2. 使用 `request.form` 函数获取用户输入的值。
3. 在表中使用 `SEEK` 命令查找该值。
4. 如果找到记录,则返回记录的值;否则,向用户显示未找到记录的消息。
### 2.3 删除记录
1. 让用户找到他们想要删除的记录。
2. 像通常一样从表中删除该记录。
## 3. 使用脚本映射替代对 WC.DLL 的调用
在之前的示例中,我们使用了包含 “wc.dll” 的长 URL 来调用 Web Connection 应用程序的方法。实际上,我们可以使用脚本映射来简化这些 URL。以下是一些示例:
| 原始 URL | 脚本映射版本 |
| --- | --- |
| `http://localhost/wr04/wc.dll?wr04process~HelloWorld` | `http://localhost/wr04/HelloWorld.wr` |
| `http://localhost/wr04/wc.dll?wr04Process~ShowStatic` | `http://localhost/wr04/ShowStatic.wr` |
| `http://localhost/wr04/wc.dll?wr04Process~GetParms` | `http://localhost/wr04/GetParms.wr` |
| `<form action="/wr04/wc.dll?wr04process~GetAndShowResults" method="post">` | `<form action="GetAndShowResults.wr" me
0
0
复制全文
相关推荐










