VBS使用recordset对象增删查改

上一篇 / 下一篇  2014-05-11 13:49:49 / 个人分类:VBScript

E{&CYi(T.j0set con =CreateObject("ADODB.connection")
1l4D-D ]I~%p(L0set rs=createobject("ADODB.recordset")51Testing软件测试网!e5n7{ u2Q'Y
strsql=“select * from tablename”51Testing软件测试网Z(x4eCIO u'`T
con.ConnectionString="此处略去30字……"
Tm \/y(S;?"S0con.open51Testing软件测试网!]vJqH4m'Q

?P^2[6f'n(x0查询
8p'Op)_D:_f1|W0rs.open strsql,con,1,2
4PQzP4]^yI0if not (rs.bof or rs.eof) then51Testing软件测试网]7c[|N2Rf%O#l;\{
strname=rs("name")51Testing软件测试网(l0a;ny-p|k A
=rs.feilds("name")
s*Ew b/Z\ r}0end if51Testing软件测试网2D7|!C(V#?qq

51Testing软件测试网/o B,cV]P7R&p

getrow:将数据集保存到二维数组
D f9Eys0strdata=rs.getrow(2,0)51Testing软件测试网 ^h6Or{
'从第一行开始复制两行到二维数组
!?,? iSr{0str(1,0)第二咧第一行51Testing软件测试网GSGHH `]U,b2v
strdata(1,1)第二列第二行
*L_w#o sii(E ds0getstring:将数据集作为字符串返回51Testing软件测试网*cY*~4nW.G
51Testing软件测试网.J:n(eJ{$PF
筛选51Testing软件测试网xEhE8rfZ
rs.filter="name='json'"51Testing软件测试网 q.ax%UkTz

R:hJ"~E b7Kz~0新增
oIf)J#os,o051Testing软件测试网Q?.P;O\*G7e
rs.addnew51Testing软件测试网!x-q,l~"G
rs("name")="张三"51Testing软件测试网+RN5BB9i,wonRZT
rs.update
\0g1V} F] P051Testing软件测试网)e5F6k @3t4^4~n9^
更新51Testing软件测试网s B;nB fU&}5W
51Testing软件测试网6q5qlv r P
rs.update "name","jhon"
{J9P%L7{|lo0rs("name")="e"
i:]w6GNs/`0rs.update(或rs.updatebatch)51Testing软件测试网#_WG5b w&J
例子:
oe8Bu7X:x(`?0count=rs.recordcount51Testing软件测试网0{#T[6S.Tb!Vk h
for i=1 to count 51Testing软件测试网G*E5k/BUQT
if rs("name")="zhangsan" then
?.vL!O?0R#vj0rs.update "name","lisi"
K)d4s)E%Z0exit for
A*j6P[\)S!|0end if51Testing软件测试网6AIJull
rs.movenext51Testing软件测试网S9E`!Q(?C-T
next51Testing软件测试网DqF _xj&wM \
set con=nothing51Testing软件测试网`6FzUo;iWV
set rs=nothing
[`(x(UN|051Testing软件测试网0a;n3G9nL N,f {e

'm:k q-@Y}n'H1d0删除
Z+e8o"h"y0? o5@_0rs.cursorlocation=351Testing软件测试网%af?1W@S `5c)DI
须在rs打开之前声明
Rd5Mm3y%dS)I3k"c;u0rs.delete 151Testing软件测试网sT[Y/YaH"`
rs.update51Testing软件测试网Dxp[/na
51Testing软件测试网;y#mY.])][


TAG:

 

评分:0

我来说两句

Open Toolbar