VB6 red write DB using Microsoft DAO 3.6 Object Library
2016-02-02 10:19
609 查看
' -----------------------------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 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
End Sub
1.Drag a Data control to the form with named "Data1"
2.Drag a TDBGrid control to the form with named "TDBGrid1"
2.Set control "TDBGrid1"'s property "DataSource" with value "Data1"
3.hen code :
Dim sysDb As Database
Private Sub Command1_Click()
Dim rsData As Recordset
Dim sPath As String
Dim rs As Recordset
sPath = App.Path + "/testDB.mdb"
Set sysDb = OpenDatabase(sPath, 3)
Set rsData = sysDb.OpenRecordset("select * from students")
Set rs = rsData.Clone
Set Data1.Recordset = rs 'must use set
TDBGrid1.Columns("id").BackColor = vbRed
'Me.TDBGrid1.ReBind
End Sub
refer link:
Database.OpenRecordset Method (DAO) link:https://msdn.microsoft.com/en-us/library/office/ff820966.aspx
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
bind data with TDBGrid (Library TrueDBGrid80 C:\WINDOWS\system32\tdbg8.oca ComponentOne True DBGrid Pro 8.0)
step:1.Drag a Data control to the form with named "Data1"
2.Drag a TDBGrid control to the form with named "TDBGrid1"
2.Set control "TDBGrid1"'s property "DataSource" with value "Data1"
3.hen code :
Dim sysDb As Database
Private Sub Command1_Click()
Dim rsData As Recordset
Dim sPath As String
Dim rs As Recordset
sPath = App.Path + "/testDB.mdb"
Set sysDb = OpenDatabase(sPath, 3)
Set rsData = sysDb.OpenRecordset("select * from students")
Set rs = rsData.Clone
Set Data1.Recordset = rs 'must use set
TDBGrid1.Columns("id").BackColor = vbRed
'Me.TDBGrid1.ReBind
End Sub
refer link:
Database.OpenRecordset Method (DAO) link:https://msdn.microsoft.com/en-us/library/office/ff820966.aspx
相关文章推荐
- objective-c 中随机数的用法 (3种:arc4random() 、random()、CCRANDOM_0_1() )
- Objective-C(十八、谓语使用及实例说明)——iOS开发基础
- springMVC 自动将form 提交对象型数据转为Object对象数据
- IOS Object-C与Swift相互调用
- JavaScript第五课——数据类型(String类型、Object类型)
- js 报错:object is not a function
- 信号与槽(可以与第三方库混用,首次见到QObject::destroyed的使用)
- the Meta-Object Compiler (moc)
- The Meta-Object System
- QThread 与 QObject的关系(QObject可以用于多线程,可以发送信号调用存在于其他线程的slot函数,但GUI类不可重入)
- WPF输入框Paste时出错,IDataObject的GetData抛出OutOfMemoryException
- java基础之 超类Object
- Swift学习之Objective-C 与 Swift 混用(1)
- The DataWindows Object not find。。。。错误提示-----------运维日志19
- json中jobject
- 使用Objective-C解压缩ZIP文件教程
- Objective Foundations
- objective-zip解压带密码的文件
- 2 类与对象
- embed区别object