标题:学会了VB中ADO的基本使用方法 出处:Felix021 时间:Tue, 25 Mar 2008 11:41:51 +0000 作者:felix021 地址:https://www.felix021.com/blog/read.php?772 内容: 蛮简单的。微软的东西总是傻瓜化了。。 简单记录一下如何读取、写入、删除。 读取: private sub read_all() dim conn as connection dim rs as recordset dim connstr, sql, dbname as string set conn = new connection dbname = app.path & "/dbname.mdb" connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbname conn.open connstr if err then msgbox "Error Connecting!" exit sub end if set rs = new recordset sql = "select top 3 * from table1" rs.open sql, conn, 1, 1 if err then msgbox "Error querying!" exit sub end if if rs.eof and rs.bof then msgbox "No record" exit sub end if label1.caption = "" while not rs.eof label1.caption = label1.caption & rs("id") & ", " & rs("name") & ", " & .............. rs.movenext wend rs.close end sub 增加(不全写了): sql = "insert into table1 (name, age, ...) values ('name',12,...)" rs.open sql, conn, 1, 3 或者: sql = "select top 1 * from table1" rs.open sql, conn, 1, 3 rs.addnew rs("name") = "name" rs("age") = 12 .. rs.update rs.close 删除: sql = "delete from table1 where id=" & id_num rs.open sql, conn, 1, 3 Generated by Bo-blog 2.1.0