基于ADO+Adodc控件+DataGrid控件制作的一个数据库编辑程序(完整原程序)

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 lshdic 的 blog

数据库数据编辑演示程序,在win98调试通过,详细请自行下载进行学习测试,程序大小29k

下载地址:http://www.lshdic.com/download/lshdic/vb_adoedit.zip

代码浏览:

dim dataname as string

private sub command1_click()
d.dialogtitle = "打开一个access数据库进行编辑"
d.filename = ""
d.initdir = app.path
d.filter = "access数据库文件mdb后缀|*.mdb"
d.showopen
if d.filename = "" then exit sub

list1.clear
set link1 = new adodb.connection                 '创建ado连接
link1.open "provider=microsoft.jet.oledb.4.0;data source=" & d.filename
set tables = link1.openschema(adschemacolumns)   '创建数据库记录集为了得到数据库中所有表名
oldtablename = ""
do while not tables.eof
if tables("table_name") <> oldtablename then
oldtablename = tables("table_name"): list1.additem oldtablename
end if
tables.movenext
loop
if list1.listcount = 0 then msgbox "数据库打开失败,或数据库不存在表", vbcritical, "错误": exit sub
dataname = d.filename
list1.enabled = true: command2.enabled = true
list1.listindex = 0: list1_click
end sub

private sub command2_click()
ldc.recordset.update    '更新ldc记录集
end sub

private sub form_resize()
edit.width = me.scalewidth - 200
edit.height = me.scaleheight - edit.top - 50
end sub

private sub list1_click()
'ldc控件连接数据源
ldc.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & dataname & ";persist security info=false"
'ldc控件使用sql命令,get数据源数据
ldc.recordsource = "select * from " & list1.text
ldc.refresh: label1.caption = "共" & ldc.recordset.recordcount & "条记录," & ldc.recordset.fields.count & "个分类字段"
end sub

本文关键:ADO Adodc DataGrid 数据库
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top