CSDN博客

img lshdic

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

发表于2003/7/12 10:51:00  1879人阅读

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

0 0

相关博文

我的热门文章

img
取 消
img