VB6 red write DB using Microsoft DAO 3.6 Object Library

1308 단어
' -----------------------------read db Private Sub Form_Load() 'MsgBox App.Path & "\wgscd.mdb"Dim tblCountry As Recordset Dim dbSys As Database Dim s As String Set dbSys = OpenDatabase(App.Path + "\wgscd.mdb", False) Set tblCountry = dbSys.OpenRecordset("Students")' OR Use like : dbSys.OpenRecordset("select * from Students") With tblCountry .MoveFirst Do While Not .EOF s = s & !sid & ";"& !Name & "score:"& .Fields("score") 'note:"!sid"is present as .Fields("sid") .MoveNext Loop
End With
MsgBox s

End Sub
'--------------write db----------------------------- Private Sub Command1_Click()
'MsgBox App.Path & "\wgscd.mdb"Dim tblCountry As Recordset Dim dbSys As Database Dim s As String Set dbSys = OpenDatabase(App.Path + "\wgscd.mdb", False) Set tblCountry = dbSys.OpenRecordset("Students") With tblCountry .AddNew !sid = 5 + rnd(500) !Name = "bb"& Now .Fields("score") = rnd(100) .Update .MoveFirst End With
 MsgBox tblCountry.RecordCount

End Sub
refer link: Database.OpenRecordset Method (DAO) link:https://msdn.microsoft.com/en-us/library/office/ff820966.aspx

좋은 웹페이지 즐겨찾기