大鸟的学习乐园
路漫漫其修远兮,吾将上下而求索
posts - 26,comments - 27,trackbacks - 0
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
posted on 2008-11-26 07:16 大鸟 阅读(381) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: