' -----------------------------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


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

VB6 red write DB using Microsoft DAO 3.6 Object Library的更多相关文章

  1. 在项目引用里添加上对Microsoft Word 11.0 object library的引用

    private void button1_Click(object sender, System.EventArgs e) { //调用打开文件对话框获取要打开的文件WORD文件,RTF文件,文本文件 ...

  2. Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: “object”未包括“get_Range”的定义

    asp.net操作Excel合并单元格时,抛出了异常: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: "object" ...

  3. java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.yunweather.app.db.YunWeatherDB.loadProvinces()' on a null object reference

    NullPointerException:查看自己的什么地方是否对空指针进行了操作 Attempt to invoke virtual method 'java.util.List com.yunwe ...

  4. go web开发(gin&gorm) 之DB配置及DAO的基本使用

    转载请注明出处: https://www.cnblogs.com/funnyzpc/p/9501376.html ```   我先闲扯下,前天(也就是2018年11月16号)的某个时候,忽然有人在QQ ...

  5. csharp: Procedure with DAO(Data Access Object) and DAL(Data Access Layer)

    sql script code: CREATE TABLE DuCardType ( CardTypeId INT IDENTITY(1,1) PRIMARY KEY, CardTypeName NV ...

  6. c#使用Microsoft Excel 12.0 object Libary导出的Excel文件office2003不能打开!!~~(分享)

    -----转载:http://hi.baidu.com/zhang_zhu_1/item/f3d47d1f86bf037a70d5e87e 使用C#导出数据到Excel文件时,Excel 2007组件 ...

  7. VB6 Access 事务(Transaction)

    VB6 Access 事务 On Error GoTo err_trans intTrans = conn.BeginTrans '开始事务 X = count For i = 0 To X sql= ...

  8. 使用VB6制作RTD函数

    以前模仿大神在vs里使用c#实现RTD函数功能.(真是很生僻的东东啊)C#制作RTD参考:大神博客跳转.最近想VB里能不能做?就试着做了做,好像基本成了,整套代码有些毛病,勉强能算个样子,暂时不打算再 ...

  9. 引用Microsoft.Office.Interop.Excel出现的问题

    引用Microsoft.Office.Interop.Excel出现的问题   转自:http://www.hccar.com/Content,2008,6,11,75.aspx,作者:方继祥 操作背 ...

随机推荐

  1. eval解析json字符串

    场景:在springMVC,手动拼接的list,转成本json字符串后,传到前台, 解决:需要解析成json对象,获取对象的属性,动态生成table. 首先,以下是后台准备好的list,list中有两 ...

  2. leetCode题解之根据字符出现的频率排序

    1.题目描述 Given a string, sort it in decreasing order based on the frequency of characters. Example 1: ...

  3. windows下建立netcore控制台程序,然后传送到centos7下的docker容器里运行

    1.首先,在window下用vs2017开发netcore控制台项目. 2.把建立好的项目传送到centos7下面的容器里. docker cp sharefoldersforwindows/ 359 ...

  4. MySQL中如何实现select top n

    用惯了access mssql server的朋友,可能在用mysql查询前N条记录时,习惯的使用select top n 形式的语句,在这里说明一下,mysql没有此语法,mysql用limit来实 ...

  5. a标签 按钮化使用

    a标签 按钮化使用 a href="javascript:void(0);" onclick="js_method()" a href="javasc ...

  6. Windows自带强大的入侵检测工具——Netstat 命令 查询是否中木马

    Netstat命令可以帮助我们了解网络的整体使用情况.根据Netstat后面参数的不同,它可以显示不同的网络连接信息.Netstat的参数如图,下面对其中一些参数进行说明.如何检测本机是否有被中木马, ...

  7. 将DataRow赋值给model中同名属性

    /// <summary> /// 将DataRow赋值给model中同名属性 /// </summary> /// <typeparam name="T&qu ...

  8. 配置consul为windows服务

    安装consul并配置为系统服务下载地址https://www.consul.io/downloads.html 配置系统服务1.拷贝consul.exe的目录 如:E:\Consul\consule ...

  9. [翻译] GoogleMaterialDesignIcons

    GoogleMaterialDesignIcons Google Material Design Icons Font for iOS GMD图片样式的字体,用于iOS开发. It is based ...

  10. [翻译] JFMinimalNotifications

    JFMinimalNotifications This is an iOS UIView for presenting a beautiful notification that is highly ...