a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 82|回复: 0

[Access] Access通用:自动替换数据库中的字符串

[复制链接]
发表于 2012-7-31 22:26:35 | 显示全部楼层 |阅读模式
自己可以修改myreplace函数,实现复杂的替换.呵呵,好象用处不大.主要是看看如何读取access表和字段列表   ;%  Q2 o( p+ x! P! z) Y0 E  c3 p
  '####################################
, P, ?. E, l. I7 z  '替换数据库内容 lamking 2005-8-22
6 h- Q6 V1 W0 `: a( t& R8 a  'http://www.lamking.com QQ:6285578 q9 c) P) a$ ]% `: Q8 Q
  '####################################
2 b; E" m* D$ ?4 z$ {  Dim Db,Connstr,conn,rs,rs2,str1,str2,I; X. C, e  I4 [
  str1="abcd" '要替换的字符串; U  d: m( a+ s1 f
  str2="1234" '替换为的字符串: P5 `% b& d5 m6 p
  Db="lamking.mdb"
0 w( ^; P( |$ L- o- i8 P1 \& d  Set conn=Server.CreateObject("ADODB.Connection")
5 m, t/ p0 G* u4 G! [/ v  ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="%26amp;server.mappath(Db): T( j$ D* s5 t/ u5 M# y1 V
  Conn.Open ConnStr
# h6 N' K/ K3 M. V- n; ~  Set rs = conn.OpenSchema(20)- m" ?) x1 C! ~8 r* @' X* {
  Do While Not rs.eof
6 }# R1 u, e/ t  If rs("TABLE_TYPE")="TABLE" Then: T1 n3 c2 O! x' B3 Q3 A, ?- o
  Set Rs2=Server.Createobject("adodb.recordset")
" j' o; |7 b2 O, R' \+ R" w  Rs2.Open "select * from ["%26amp;rs("TABLE_NAME")%26amp;"]",conn,1,3. c, `# Q  R* ?% R
  Do While Not Rs2.Eof8 c  S  E7 s! ^# |4 S" w% h2 I0 z
  For I=0 to Rs2.fields.count-17 t; d8 ~) U, E' x" Y6 t( s
  If Rs2(i).Properties("ISAUTOINCREMENT") = False Then. @4 U% [- @# A+ D" a
  Rs2(Rs2(i).name)=Myreplace(Rs2(i).value)9 W' D: M$ I* x3 q9 I% s( s# q
  End If. D+ L) v" f  ~+ C
  Next
5 ?, g8 h- N/ M+ h5 p/ I  Rs2.Movenext& ], U! f7 l% `
  Loop% j1 n$ z) c& j8 K/ Y9 j
  Rs2.Close
, O7 q5 i7 c- _/ L/ q  Set Rs2=nothing# b0 U& Z; A' f9 S( A  K0 O- h' z
  End If& ]# Y! ?% N; I# I0 P
  Rs.Movenext
+ F% s9 g& S5 T3 }' F3 M9 G  Loop
% O% P" Y; z+ q! ]' M  Rs.close& A# [0 L3 X- N, G
  Set Rs=nothing+ Y7 q! C* t8 O  h# E1 a+ m! T
  Conn.close% {5 w. n- l3 f+ i
  Set Conn=nothing
1 G5 C+ N$ r, y' F/ q  Response.Write"替换完成"* l7 z# @" [; [' f0 M+ M
  Function myreplace(byval Tstr)
* L* |" F# i- G: `+ H7 C  a( n  If Tstr="" Or isnull(Tstr) Then
- U/ s% }4 V& S' l8 b  Exit Function7 _: i$ }' m- _  w
  Else
' j- Q7 [8 c! J+ z  myReplace=replace(Tstr,str1,str2)
# y* a6 y$ ]& z; G- s8 n7 M  T1 C  End If
# ~, F1 j& b! s1 l8 }4 a  End Function
$ [3 E. N' N* X  s' P3 V' ~  %;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-7 17:38 , Processed in 0.203211 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表