博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB6 red write DB using Microsoft DAO 3.6 Object Library
阅读量:5265 次
发布时间:2019-06-14

本文共 1738 字,大约阅读时间需要 5 分钟。

' -----------------------------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 WithMsgBox 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://www.cnblogs.com/wgscd/p/5176887.html

你可能感兴趣的文章
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>
CF1215E Marbles
查看>>
.net Core 图片验证码 基于SkiaSharp实现
查看>>
fish redux 个人理解
查看>>
java 笔记一些
查看>>
BZOJ2339 HNOI2011卡农(动态规划+组合数学)
查看>>
octave基本操作
查看>>
排球计分程序重构(一)
查看>>
axure学习点
查看>>
WPF文本框只允许输入数字[转]
查看>>
dom4j 通用解析器,解析成List<Map<String,Object>>
查看>>
第一个项目--用bootstrap实现美工设计的首页
查看>>
使用XML传递数据
查看>>
TYVJ.1864.[Poetize I]守卫者的挑战(概率DP)
查看>>
基于CMMI的敏捷开发过程文档裁剪
查看>>
0925 韩顺平java视频
查看>>
软件需求规格说明书
查看>>
53. Maximum Subarray
查看>>