Mar 25

学会了VB中ADO的基本使用方法 不指定

felix021 @ 2008-3-25 11:41 [IT » 数据库] 评论(0) , 引用(0) , 阅读(4739) | Via 本站原创 | |
蛮简单的。微软的东西总是傻瓜化了。。

简单记录一下如何读取、写入、删除。

读取:
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



欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]