大鳥的學習樂園
          路漫漫其修遠兮,吾將上下而求索
          posts - 26,comments - 27,trackbacks - 0
          Dim dataname As String
          Private Sub Command1_Click()
          d.DialogTitle = "打開一個Access數(shù)據(jù)庫進行編輯"
          d.FileName = ""
          d.InitDir = App.Path
          d.Filter = "Access數(shù)據(jù)庫文件MDB后綴|*.mdb"
          d.ShowOpen
          If d.FileName = "" Then Exit Sub
          list1.Clear
          Set link1 = New ADODB.Connection                 '創(chuàng)建ADO連接
          link1.Open "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & d.FileName
          Set tables = link1.OpenSchema(adSchemaColumns)   '創(chuàng)建數(shù)據(jù)庫記錄集為了得到數(shù)據(jù)庫中所有表名
          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 "數(shù)據(jù)庫打開失敗,或數(shù)據(jù)庫不存在表", 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控件連接數(shù)據(jù)源
          ldc.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" & dataname & ";Persist Security Info=False"
          'ldc控件使用SQL命令,GET數(shù)據(jù)源數(shù)據(jù)
          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 大鳥 閱讀(393) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 尖扎县| 洪雅县| 新野县| 礼泉县| 天水市| 盐亭县| 定安县| 鲜城| 肥东县| 龙海市| 南澳县| 宁阳县| 姚安县| 仲巴县| 海原县| 红桥区| 绥阳县| 梁河县| 永春县| 金华市| 台安县| 平谷区| 康马县| 连江县| 哈巴河县| 临西县| 岗巴县| 黑山县| 贵州省| 敖汉旗| 舒城县| 刚察县| 治县。| 故城县| 即墨市| 上思县| 景泰县| 阿图什市| 顺平县| 赞皇县| 忻州市|