使用方法:保存为asptools.hta然后再运行
代码如下:
<!doctype html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-
transitional.dtd>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=content-type content=text/html; charset=gb2312 />
<meta name=author content=柳永法 />
<title>asp辅助工具</title>
<style>body{ font-size:12px}</style>
<hta:application
id=asptools
applicationname=asptools
scroll=no
singleinstance=yes
windowstate=normal
>
</head>
<body>
<div>
<input type=file id=txtfile onchange=createtableselect('access') style=display:none />
ip:<input type=text name=ip size=16 style=border:1px solid green value=.\sql2005 />
登录名:<input type=text name=userid size=10 style=border:1px solid green value=sa />
密码:<input type=password name=pwd size=10 style=border:1px solid green value=yongfa365 />
数据库名:<input type=text name=dbname size=10 style=border:1px solid green value=hb605-8-8 /><br />
<input name=button2 type=button id=button2 style=border:1px solid green onclick=createtableselect
('mssql') value=连接sql数据库 />
<input type=button id=btnfromfile onclick=txtfile.click() value=连接access数据库 style=border:1px solid
green />
<span id=tables ></span>
<hr />
模板:
<input type=text id=opt value= size=40 />
<select size=1 id=fz onchange=opt.value=this.value style=width:200px></select>
<input name=button type=button id=button onclick=c() value=转换 style=border:1px solid green>
<hr />
<textarea id=s rows=10 cols=80 style=width:98%></textarea>
<input type=button onclick=madesql() value=生成sql语句 style=border:1px solid green />
<textarea id=d rows=10 cols=80 style=width:98%></textarea>
</div>
<pre id=sqldemo style=display:none intro=通用建表结构>
--通用建表结构
create table [dbo].[tablename] (
[id] int primary key identity(1,1),--id,主键,自动号
[txttitle] varchar(255),--标题
[txtcontent] text,--内容
[puttime] datetime default (getdate()),--提交时间
[moditime] datetime default (getdate()),--修改时间
[hits] int default (0),--点击数
[flags] int default (0) ,--标识
[orderid] int default (0),--排序号
)
</pre>
<pre id=sdemo style=display:none intro=初始源测试数据>
username
password
sex
truename
age
tel
msn
</pre>
<pre id=fzdemo style=display:none intro=辅助输入>
辅助输入
rs($1) = request($1)
rs($1) = saferequest($1)
$1 = request($1)
$1 = saferequest($1)
<tr><td>$1:</td><td><input type=text name=$1 size=20></td></tr>
</pre>
<hr />
建议查看源文件然后保存为asptools.hta然后再运行
<script language=vbscript type=text/vbscript>
self.focus()
self.resizeto 620, 520
'初始化数据
s.value = sdemo.innerhtml
fzs = split(fzdemo.innerhtml, vbcrlf)
for each opttemp in fzs
set o = document.createelement(option)
o.text = opttemp
o.value = opttemp
fz.add o
next
opt.value = fz.options(1).value
'程序运行时的一些函数
function c()
ss = split(s.value, vbcrlf)
for each sss in ss
if sss<> then str = str & replace(opt.value, $1, sss) & vbcrlf
next
d.value = str
end function
dim xcat '定义全局变量,避免重复链接数据库。
function createtableselect(dbtype)
set xcat = createobject(adox.catalog)
if dbtype = access then
xcat.activeconnection = provider=microsoft.jet.oledb.4.0;data source= & txtfile.value
elseif dbtype = mssql then
xcat.activeconnection = provider=sqloledb.1; persist security info=true; data source= & ip.value & ;
initial catalog=& dbname.value &; user id=& userid.value &; password= & pwd.value
end if
for each xtable in xcat.tables
tabletype = xtable.type
if tabletype = table then
tabless = tabless & <option value='& xtable.name &'>& xtable.name &</option>
end if
next
tables.innerhtml = <select name='nowtables' onchange='createfieldselect( & dbtype & )'><option>==请选择
表名==</option> & tabless & </select>
end function
function createfieldselect(dbtype)
dim item
for each xtable in xcat.tables
if xtable.name = nowtables.value then
for each item in xtable.columns
str = str + item.name & vbcrlf
next
exit for
end if
next
s.value = left(str, len(str) -2)
end function
function madesql()
yongfa365fields = split(s.value, vbcrlf)
yongfa365code2 =
for each sql in yongfa365fields
if sql<> then strsql = strsql & [ & sql & ] varchar(50),
next
strsql = left(strsql, len(strsql) -1)
yongfa365code2 = create table tablename( & vbcrlf & replace(strsql, ,, , & vbcrlf) & vbcrlf & ) & vbcrlf
& vbcrlf
tempvalue = join(yongfa365fields, & ',' & objitem.)
yongfa365code2 = yongfa365code2 & conn.execute insert into info ( & join(yongfa365fields, ,) & ) values
(' & objitem. & tempvalue & & ') & vbcrlf & vbcrlf & vbcrlf
tempvalue = join(yongfa365fields, ) & ',' & rs()
yongfa365code2 = yongfa365code2 & conn.execute insert into info ( & join(yongfa365fields, ,) & ) values
(' & rs( & tempvalue & ) & ') & vbcrlf & vbcrlf & vbcrlf
tempvalue = join(yongfa365fields, & ',' & )
yongfa365code2 = yongfa365code2 & conn.execute insert into info ( & join(yongfa365fields, ,) & ) values
(' & & tempvalue & & ') & vbcrlf & vbcrlf & vbcrlf
d.value = sqldemo.innerhtml & string(2, vbcrlf) & yongfa365code2
end function
function rereplace(str, restrs, restrd)
set re = new regexp
re.ignorecase = true
re.global = true
re.pattern = restrs
rereplace = re.replace(str, restrd)
end function
</script>
</body>
</html>