数据库数据编辑演示程序,在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