正在阅读:VB中远程数据库的访问(3) 应用举例VB中远程数据库的访问(3) 应用举例

2004-02-14 09:34 出处:eNet学院 作者:许蔓舒 责任编辑:pjl
private sub cmdend_click() end ’ 结 束 应 用 程 序 end sub private sub cmdmodify_click() dbgrid1.allowupdate = true ’ 允 许 修 改 end sub privatev sub cmd 链 接_click() form1.hide form2.show end sub private sub dbgrid1_aftercolupdate(byval colindex as integer) ’ 数 据 修 改 后 触 发 该 事 件 on error goto err1 data1.refresh err1: select case err case 0 response = 0 case else exit sub end select end sub private sub dbgrid1_beforecolupdate (byval colindex as integer, oldvalue as variant, cancel as integer) ’ 数 据 修 改 前 触 发 该 事 件 on error goto errhandler: begintrans if msgbox(" 确 实 要 修 改 这 一 内 容 ?", vbquestion + vbyesno) = vbyes then committrans else rollback data1.refresh end if errhandler: select case err case 0 response = 0 case else msgbox (error) exit sub end select end sub private sub form_load() ’ 在 窗 体 装 入 时, 网 格 中 的 数 据 不 可 添 加, 修 改 dbgrid1.allowaddnew = false dbgrid1.allowupdate = false end sub private sub form_resize() on error resume next ’ 当 窗 体 调 整 时 会 调 整 网 格 dbgrid1.height = me.scaleheight - data1.height - cmd 删 除.height - 30 end sub 在工程中添加一个窗体,在窗体上画6个标签,1个命令按钮(标题为“ 确认”,名称为cmd 确认),3个文本框和1个组合框。 在窗体的声明部份输入以下代码: ’ 声 明 窗 体 层 变 量 dim rodbs as database dim strdb as string, strrodb as string, strcn as string, strtdf as string dim linktdfname as string 编 写 如 下 事 件 过 程: private sub cmd 确 认_click() on error goto errhandler: strdb = text2.text ’ 本 地 数 据 库 名 及 路 径 linktdfname = text3.text ’ 本 地 数 据 库 中 新 建 的 链 接 远 程 表 的 表 名 strcn = strrodb ’ 连 接 字 符 串 strtdf = combo1.text ’ 指 定 远 程 数 据 库 中 要 访 问 的 表 ’ 调 用linktable 过 程 call linktable(strdb, strrodb, strcn, strtdf, linktdfname) ’ 调 用rst_display 过 程 call rst_display(strdb, linktdfname, form1) form2.hide form1.show form1.caption = " 远 程 数 据:" + strcn + "-" + strtdf ’ 显 示“ 添 加”,“ 删 除”,“ 修 改” 控 件 form1.cmdadd.visible = true form1.cmddel.visible = true form1.cmdmodify.visible = true errhandler: select case err case 0 response = 0 case else msgbox (error + vbr + " 重 新 输 入") exit sub end select end sub private sub combo1_gotfocus() strrodb = text1.text ’ 指 定 远 程 数 据 库 名 及 路 径 set rodbs = opendatabase(strrodb) ’ 打 开 远 程 数 据 库 ’ 删 除combo1 中 的 内 容 if combo1.listcount >= 1 then for i = combo1.listcount - 1 to 0 step -1 combo1.removeitem i next i end if ’ 把 数 据 库 中 的 表 名 加 到combo1 中 for i = 0 to rodbs.tabledefs.count - 1 combo1.additem rodbs.tabledefs(i).name next i end sub
键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品