当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbs生成ACCESS数据里所有表的字段

vbs生成ACCESS数据里所有表的字段

2017年12月12日  | 移动技术网IT编程  | 我要评论
<job id ="生成access数据库里所有表及所有字段并生成一定格式的字符组合">
<script language ="vbscript">
databasename ="access.mdb"''数据库地址
tablename ="blogarticle"''要处理的表名


set conn = createobject("adodb.connection")
connstr ="provider=microsoft.jet.oledb.4.0;data source="&databasename
conn.open connstr

set rs_all = createobject("adodb.recordset")
sql_all ="select name from msysobjects where type=1 and flags=0"
rs_all.open sql_all, conn,1,1

dowhilenot rs_all.eof
    tablename = rs_all(0)
set rs = createobject("adodb.recordset")
    sql ="select * from "& tablename &" where 1<>1"
    rs.open sql, conn,1,1
    j = rs.fields.count
    txtcontent =""
    txtcontent1 =""
    txtcontent2 =""
    txtcontent3 =""
    txtcontent4 =""
for i =0to(j -1)
        title = rs.fields(i).name
        txtcontent = txtcontent & title &"|"
        txtcontent1 = txtcontent1 & title&"=trim(request("""&title&"""))"&"<br>"
        txtcontent2 = txtcontent2 & title&"=rs("""&title&""")<br>"
        txtcontent3 = txtcontent3 &"rs("""&title&""")=trim(request("""&title&"""))<br>"
        txtcontent4 = txtcontent4 & title&"=rs("""&title&""")<br>"
next
    yongfa365 ="<div align=center><a href=""http://www.yongfa365.com"" class=""titlink"" title=""柳永法(yongfa365)'blog http://www.yongfa365.com"">柳永法(yongfa365)'blog</a>制作</div>"&title&"里的字段<br><br>"
    createfile tablename&".html", yongfa365 & txtcontent &"<br><br>"& txtcontent1 &"<br><br>"& txtcontent2 &"<br><br>"& txtcontent3 &"<br><br>"& txtcontent4
    rs_all.movenext
loop

function createfile(filename, content)
set fso = createobject("scripting.filesystemobject")
set fd = fso.createtextfile(filename,true)
    fd.writeline content
endfunction

</script>
</job>


<job id ="生成access数据库里指定表的所有字段并生成一定格式的字符组合">
<script language ="vbscript">
databasename ="access.mdb"''数据库地址
tablename ="blogarticle"''要处理的表名


set conn = createobject("adodb.connection")
connstr ="provider=microsoft.jet.oledb.4.0;data source="&databasename
conn.open connstr

''set rs_all = createobject("adodb.recordset")
''sql_all = "select name from msysobjects where type=1 and flags=0"
''rs_all.open sql_all, conn, 1, 1

''do while not rs_all.eof
''    tablename = rs_all(0)
set rs = createobject("adodb.recordset")
sql ="select * from "& tablename &" where 1<>1"
rs.open sql, conn,1,1
j = rs.fields.count
txtcontent =""
txtcontent1 =""
txtcontent2 =""
txtcontent3 =""
txtcontent4 =""
for i =0to(j -1)
    title = rs.fields(i).name
    txtcontent = txtcontent & title &"|"
    txtcontent1 = txtcontent1 & title&"=trim(request("""&title&"""))"&"<br>"
    txtcontent2 = txtcontent2 & title&"=rs("""&title&""")<br>"
    txtcontent3 = txtcontent3 &"rs("""&title&""")=trim(request("""&title&"""))<br>"
    txtcontent4 = txtcontent4 & title&"=rs("""&title&""")<br>"
next
yongfa365 ="<div align=center><a href=""http://www.yongfa365.com"" class=""titlink"" title=""柳永法(yongfa365)'blog http://www.yongfa365.com"">柳永法(yongfa365)'blog</a>制作</div>"&title&"里的字段<br><br>"
createfile tablename&".html", yongfa365 & txtcontent &"<br><br>"& txtcontent1 &"<br><br>"& txtcontent2 &"<br><br>"& txtcontent3 &"<br><br>"& txtcontent4
''    rs_all.movenext
''loop

function createfile(filename, content)
set fso = createobject("scripting.filesystemobject")
set fd = fso.createtextfile(filename,true)
    fd.writeline content
endfunction

</script>
</job>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网